GitLab Module – Infra API
POST /gitlab/init-project (Not for Dev/Local Usage)
Summary
Initialize a new client project setup in GitLab by:
- Creating a subgroup (if not exists)
- Cloning a predefined template into a new project repo
- Creating an empty K3s config repo
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| gitProjectRefType | string | ✅ | Refers to entity type (e.g., client, org) used in the subgroup path |
| gitProjectRefID | string | ✅ | Numeric string representing the entity ID |
| gitProjectTemplateID | string | ✅ | GitLab project ID of the template to clone from |
Example
{
"gitProjectRefType": "client",
"gitProjectRefID": "101",
"gitProjectTemplateID": "123456"
}
Responses
-
201 CreatedProject initialized successfully. -
400 Bad RequestInput validation failed or subgroup/project creation failed.
GET /gitlab/project-templates
Summary
Fetches a list of GitLab template projects from the database.
Responses
-
200 OKReturns an array of template projects. -
400 Bad RequestFailed to retrieve data.
POST /gitlab/project-templates (Not for Dev/Local Usage)
Summary
Syncs the local database with template repositories found in the GitLab source group.
Responses
-
200 OKIndicates how many templates were processed and updated. -
400 Bad RequestSync failed due to network or GitLab API issues.
Logic Overview (GitLabService)
Initialization Flow (initProject)
- Checks if a GitGroup exists for
ref_typeandref_id. - If not, creates a GitLab subgroup.
- Clones a project from the provided template into the subgroup.
- Initializes an empty repo for K3s config in the same subgroup.
- Stores both projects in the local DB (via
gitProject). - Links them to a
gitGroup(new or existing).
Key Helpers
createSubGroup: Ensures idempotent subgroup creation.copyTemplateProject: Performs a full Git clone → reset history → push to new repo.createEmptyRepo: Creates a blank GitLab repo with README.
Environment Variables Used
| Variable | Description |
|---|---|
GITLAB_BASE_URL | Base GitLab API endpoint |
GITLAB_TOKEN | GitLab private token for authentication |
GITLAB_SOURCE_GROUP_ID | GitLab group ID where templates are stored |
GITLAB_TARGET_GROUP_ID | GitLab group ID under which new subgroups go |
Directory Structure
apps/infra/src/api/gitlab/
├── dtos/
│ └── init-project.dto.ts # DTO for project init API
├── gitlab.controller.ts # REST API entrypoint
├── gitlab.module.ts # Module definition
├── gitlab.service.ts # Core logic for GitLab interaction