@@ -33,17 +33,18 @@ const (
3333// - version: whether to show the version
3434// - retry: the number of retries for the GitLab API requests
3535type ParserArgs struct {
36- SourceGitlabURL string
37- SourceGitlabToken string
38- SourceGitlabIsBig bool
39- DestinationGitlabURL string
40- DestinationGitlabToken string
41- DestinationGitlabIsBig bool
42- MirrorMapping * MirrorMapping
43- Verbose bool
44- NoPrompt bool
45- DryRun bool
46- Retry int
36+ SourceGitlabURL string
37+ SourceGitlabToken string
38+ SourceGitlabIsBig bool
39+ DestinationGitlabURL string
40+ DestinationGitlabToken string
41+ DestinationGitlabIsBig bool
42+ DestinationGitlabForcePremium bool
43+ MirrorMapping * MirrorMapping
44+ Verbose bool
45+ NoPrompt bool
46+ DryRun bool
47+ Retry int
4748}
4849
4950// ProjectMirrorOptions defines how the project should be mirrored
@@ -72,25 +73,33 @@ type MirrorMapping struct {
7273 muGroups sync.RWMutex
7374}
7475
76+ // AddProject adds a project to the mapping
77+ // It takes the project name and the mirroring options as parameters
78+ // It locks the projects mutex to ensure thread safety
7579func (m * MirrorMapping ) AddProject (project string , options * MirroringOptions ) {
7680 m .muProjects .Lock ()
7781 defer m .muProjects .Unlock ()
7882 m .Projects [project ] = options
7983}
8084
85+ // AddGroup adds a group to the mapping
86+ // It takes the group name and the mirroring options as parameters
87+ // It locks the groups mutex to ensure thread safety
8188func (m * MirrorMapping ) AddGroup (group string , options * MirroringOptions ) {
8289 m .muGroups .Lock ()
8390 defer m .muGroups .Unlock ()
8491 m .Groups [group ] = options
8592}
8693
94+ // GetProject retrieves the mirroring options for a project
8795func (m * MirrorMapping ) GetProject (project string ) (* MirroringOptions , bool ) {
8896 m .muProjects .RLock ()
8997 defer m .muProjects .RUnlock ()
9098 options , ok := m .Projects [project ]
9199 return options , ok
92100}
93101
102+ // GetGroup retrieves the mirroring options for a group
94103func (m * MirrorMapping ) GetGroup (group string ) (* MirroringOptions , bool ) {
95104 m .muGroups .RLock ()
96105 defer m .muGroups .RUnlock ()
@@ -167,6 +176,9 @@ func (m *MirrorMapping) checkProjects(errChan chan error) {
167176 }
168177}
169178
179+ // checkCopyPaths checks if the source and destination paths are valid
180+ // It checks if the paths are not empty, do not start or end with a slash,
181+ // and if the destination path is in a namespace for projects
170182func checkCopyPaths (sourcePath string , destinationPath string , pathType string , errChan chan error ) {
171183 // Ensure the source project path and destination path are not empty
172184 if sourcePath == "" || destinationPath == "" {
@@ -191,6 +203,8 @@ func checkCopyPaths(sourcePath string, destinationPath string, pathType string,
191203 }
192204}
193205
206+ // checkGroups checks if the groups are valid
207+ // It checks if the group names and destination paths are valid
194208func (m * MirrorMapping ) checkGroups (errChan chan error ) {
195209 duplicateDestinationFinder := make (map [string ]struct {}, len (m .Groups ))
196210 for group , options := range m .Groups {
@@ -212,6 +226,8 @@ func (m *MirrorMapping) checkGroups(errChan chan error) {
212226 }
213227}
214228
229+ // checkVisibility checks if the visibility string is valid
230+ // It checks if the visibility string is one of the valid GitLab visibility values
215231func checkVisibility (visibility string ) bool {
216232 var valid bool
217233 switch visibility {
@@ -227,6 +243,8 @@ func checkVisibility(visibility string) bool {
227243 return valid
228244}
229245
246+ // ConvertVisibility converts a visibility string to a gitlab.VisibilityValue
247+ // It returns the corresponding gitlab.VisibilityValue or gitlab.PublicVisibility if the string is invalid
230248func ConvertVisibility (visibility string ) gitlab.VisibilityValue {
231249 switch visibility {
232250 case string (gitlab .PublicVisibility ):
@@ -240,6 +258,8 @@ func ConvertVisibility(visibility string) gitlab.VisibilityValue {
240258 }
241259}
242260
261+ // StringArraysMatchValues checks if two string arrays match in values
262+ // It returns true if both arrays have the same values, regardless of order
243263func StringArraysMatchValues (array1 []string , array2 []string ) bool {
244264 if len (array1 ) != len (array2 ) {
245265 return false
0 commit comments