@@ -11,11 +11,15 @@ import (
1111 "go.uber.org/zap"
1212)
1313
14+ // ============================================================ //
15+ // GROUP CREATION FUNCTIONS //
16+ // ============================================================ //
17+
1418// createGroups creates GitLab groups in the destination GitLab instance based on the mirror mapping.
1519// It retrieves the source group path for each destination group and creates the group in the destination instance.
1620// The function also handles the copying of group avatars from the source to the destination instance.
1721func (destinationGitlab * GitlabInstance ) createGroups (sourceGitlab * GitlabInstance , mirrorMapping * utils.MirrorMapping ) error {
18- zap .L ().Debug ("Creating groups in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ))
22+ zap .L ().Info ("Creating groups in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ))
1923
2024 // Reverse the mirror mapping to get the source group path for each destination group
2125 reversedMirrorMap , destinationGroupPaths := sourceGitlab .reverseGroupMirrorMap (mirrorMapping )
@@ -71,10 +75,48 @@ func (destinationGitlab *GitlabInstance) createGroup(destinationGroupPath string
7175 return destinationGroup , nil
7276}
7377
78+ // createGroupFromSource creates a GitLab group in the destination GitLab instance based on the source group.
79+ // It sets the group name, path, description, visibility, and default branch based on the source group.
80+ // The function also handles the setting of the parent ID for the group.
81+ // It returns the created group or an error if the creation fails.
82+ func (g * GitlabInstance ) createGroupFromSource (sourceGroup * gitlab.Group , copyOptions * utils.MirroringOptions ) (* gitlab.Group , error ) {
83+ groupCreationArgs := & gitlab.CreateGroupOptions {
84+ Name : & sourceGroup .Name ,
85+ Path : & sourceGroup .Path ,
86+ Description : & sourceGroup .Description ,
87+ Visibility : & sourceGroup .Visibility ,
88+ DefaultBranch : & sourceGroup .DefaultBranch ,
89+ }
90+
91+ // Retrieve the parent namespace ID for the group
92+ // This is used to set the parent ID for the group
93+ zap .L ().Debug ("Retrieving group namespace ID" , zap .String (ROLE , ROLE_DESTINATION ), zap .String (ROLE_DESTINATION , copyOptions .DestinationPath ))
94+ parentGroupID , err := g .getParentNamespaceID (copyOptions .DestinationPath )
95+ if err != nil {
96+ return nil , err
97+ } else if parentGroupID >= 0 {
98+ groupCreationArgs .ParentID = & parentGroupID
99+ }
100+
101+ // Create the group in the destination GitLab instance
102+ zap .L ().Debug ("Creating group in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ), zap .String (ROLE_DESTINATION , copyOptions .DestinationPath ))
103+ destinationGroup , _ , err := g .Gitlab .Groups .CreateGroup (groupCreationArgs )
104+ if err == nil {
105+ zap .L ().Info ("Group created" , zap .String ("group" , destinationGroup .WebURL ))
106+ g .addGroup (destinationGroup )
107+ }
108+
109+ return destinationGroup , err
110+ }
111+
112+ // ============================================================ //
113+ // PROJECT CREATION FUNCTIONS //
114+ // ============================================================ //
115+
74116// createProjects creates GitLab projects in the destination GitLab instance based on the mirror mapping.
75117// It retrieves the source project path for each destination project and creates the project in the destination instance.
76118func (destinationGitlab * GitlabInstance ) createProjects (sourceGitlab * GitlabInstance , mirrorMapping * utils.MirrorMapping ) error {
77- zap .L ().Debug ("Creating projects in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ))
119+ zap .L ().Info ("Creating projects in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ))
78120
79121 // Create a wait group to wait for all goroutines to finish
80122 var wg sync.WaitGroup
@@ -171,46 +213,16 @@ func (g *GitlabInstance) createProjectFromSource(sourceProject *gitlab.Project,
171213 zap .L ().Debug ("Creating project in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ), zap .String (ROLE_DESTINATION , copyOptions .DestinationPath ))
172214 destinationProject , _ , err := g .Gitlab .Projects .CreateProject (projectCreationArgs )
173215 if err == nil {
174- zap .L ().Debug ("Project created" , zap .String ("project" , destinationProject .HTTPURLToRepo ))
216+ zap .L ().Info ("Project created" , zap .String ("project" , destinationProject .HTTPURLToRepo ))
175217 g .addProject (destinationProject )
176218 }
177219
178220 return destinationProject , nil
179221}
180222
181- // createGroupFromSource creates a GitLab group in the destination GitLab instance based on the source group.
182- // It sets the group name, path, description, visibility, and default branch based on the source group.
183- // The function also handles the setting of the parent ID for the group.
184- // It returns the created group or an error if the creation fails.
185- func (g * GitlabInstance ) createGroupFromSource (sourceGroup * gitlab.Group , copyOptions * utils.MirroringOptions ) (* gitlab.Group , error ) {
186- groupCreationArgs := & gitlab.CreateGroupOptions {
187- Name : & sourceGroup .Name ,
188- Path : & sourceGroup .Path ,
189- Description : & sourceGroup .Description ,
190- Visibility : & sourceGroup .Visibility ,
191- DefaultBranch : & sourceGroup .DefaultBranch ,
192- }
193-
194- // Retrieve the parent namespace ID for the group
195- // This is used to set the parent ID for the group
196- zap .L ().Debug ("Retrieving group namespace ID" , zap .String (ROLE , ROLE_DESTINATION ), zap .String (ROLE_DESTINATION , copyOptions .DestinationPath ))
197- parentGroupID , err := g .getParentNamespaceID (copyOptions .DestinationPath )
198- if err != nil {
199- return nil , err
200- } else if parentGroupID >= 0 {
201- groupCreationArgs .ParentID = & parentGroupID
202- }
203-
204- // Create the group in the destination GitLab instance
205- zap .L ().Debug ("Creating group in GitLab Instance" , zap .String (ROLE , ROLE_DESTINATION ), zap .String (ROLE_DESTINATION , copyOptions .DestinationPath ))
206- destinationGroup , _ , err := g .Gitlab .Groups .CreateGroup (groupCreationArgs )
207- if err == nil {
208- zap .L ().Debug ("Group created" , zap .String ("group" , destinationGroup .WebURL ))
209- g .addGroup (destinationGroup )
210- }
211-
212- return destinationGroup , err
213- }
223+ // ============================================================ //
224+ // RELEASES CREATION FUNCTIONS //
225+ // ============================================================ //
214226
215227// mirrorReleases mirrors releases from the source project to the destination project.
216228// It fetches existing releases from the destination project and creates new releases for those that do not exist.
@@ -279,6 +291,10 @@ func (destinationGitlab *GitlabInstance) mirrorReleases(sourceGitlab *GitlabInst
279291 return utils .MergeErrors (errorChan , 2 )
280292}
281293
294+ // ============================================================ //
295+ // CI/CD CATALOG FUNCTIONS //
296+ // ============================================================ //
297+
282298// addProjectToCICDCatalog adds a project to the CI/CD catalog in the destination GitLab instance.
283299// It uses a GraphQL mutation to create the catalog resource for the project.
284300func (g * GitlabInstance ) addProjectToCICDCatalog (project * gitlab.Project ) error {
0 commit comments