Skip to main content

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

FieldTypeRequiredDescription
gitProjectRefTypestringRefers to entity type (e.g., client, org) used in the subgroup path
gitProjectRefIDstringNumeric string representing the entity ID
gitProjectTemplateIDstringGitLab project ID of the template to clone from

Example

{
"gitProjectRefType": "client",
"gitProjectRefID": "101",
"gitProjectTemplateID": "123456"
}

Responses

  • 201 Created Project initialized successfully.

  • 400 Bad Request Input validation failed or subgroup/project creation failed.


GET /gitlab/project-templates

Summary

Fetches a list of GitLab template projects from the database.

Responses

  • 200 OK Returns an array of template projects.

  • 400 Bad Request Failed 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 OK Indicates how many templates were processed and updated.

  • 400 Bad Request Sync failed due to network or GitLab API issues.


Logic Overview (GitLabService)

Initialization Flow (initProject)

  1. Checks if a GitGroup exists for ref_type and ref_id.
  2. If not, creates a GitLab subgroup.
  3. Clones a project from the provided template into the subgroup.
  4. Initializes an empty repo for K3s config in the same subgroup.
  5. Stores both projects in the local DB (via gitProject).
  6. 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

VariableDescription
GITLAB_BASE_URLBase GitLab API endpoint
GITLAB_TOKENGitLab private token for authentication
GITLAB_SOURCE_GROUP_IDGitLab group ID where templates are stored
GITLAB_TARGET_GROUP_IDGitLab 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