@@ -13,6 +13,8 @@ import (
1313 "os"
1414 "strings"
1515 "sync"
16+
17+ gitlab "gitlab.com/gitlab-org/api/client-go"
1618)
1719
1820// ParserArgs defines the command line arguments
@@ -42,21 +44,12 @@ type ParserArgs struct {
4244// - destination_url: the URL of the destination GitLab instance
4345// - ci_cd_catalog: whether to add the project to the CI/CD catalog
4446// - issues: whether to mirror the issues
45- type ProjectMirroringOptions struct {
46- DestinationPath string `json:"destination_path"`
47- CI_CD_Catalog bool `json:"ci_cd_catalog"`
48- Issues bool `json:"issues"`
49- }
50-
51- // GroupMirrorOptions defines how the group should be mirrored
52- // to the destination GitLab instance
53- // - destination_url: the URL of the destination GitLab instance
54- // - ci_cd_catalog: whether to add the group to the CI/CD catalog
55- // - issues: whether to mirror the issues
56- type GroupMirroringOptions struct {
57- DestinationPath string `json:"destination_path"`
58- CI_CD_Catalog bool `json:"ci_cd_catalog"`
59- Issues bool `json:"issues"`
47+ type MirroringOptions struct {
48+ DestinationPath string `json:"destination_path"`
49+ CI_CD_Catalog bool `json:"ci_cd_catalog"`
50+ Issues bool `json:"issues"`
51+ MirrorTriggerBuilds bool `json:"mirror_trigger_builds"`
52+ Visibility string `json:"visibility"`
6053}
6154
6255// MirrorMapping defines the mapping of projects and groups
@@ -65,19 +58,19 @@ type GroupMirroringOptions struct {
6558// - projects: a map of project names to their mirroring options
6659// - groups: a map of group names to their mirroring options
6760type MirrorMapping struct {
68- Projects map [string ]* ProjectMirroringOptions `json:"projects"`
69- Groups map [string ]* GroupMirroringOptions `json:"groups"`
61+ Projects map [string ]* MirroringOptions `json:"projects"`
62+ Groups map [string ]* MirroringOptions `json:"groups"`
7063 muProjects sync.Mutex
7164 muGroups sync.Mutex
7265}
7366
74- func (m * MirrorMapping ) AddProject (project string , options * ProjectMirroringOptions ) {
67+ func (m * MirrorMapping ) AddProject (project string , options * MirroringOptions ) {
7568 m .muProjects .Lock ()
7669 defer m .muProjects .Unlock ()
7770 m .Projects [project ] = options
7871}
7972
80- func (m * MirrorMapping ) AddGroup (group string , options * GroupMirroringOptions ) {
73+ func (m * MirrorMapping ) AddGroup (group string , options * MirroringOptions ) {
8174 m .muGroups .Lock ()
8275 defer m .muGroups .Unlock ()
8376 m .Groups [group ] = options
@@ -88,8 +81,8 @@ func (m *MirrorMapping) AddGroup(group string, options *GroupMirroringOptions) {
8881// It returns the mapping and an error if any
8982func OpenMirrorMapping (path string ) (* MirrorMapping , error ) {
9083 mapping := & MirrorMapping {
91- Projects : make (map [string ]* ProjectMirroringOptions ),
92- Groups : make (map [string ]* GroupMirroringOptions ),
84+ Projects : make (map [string ]* MirroringOptions ),
85+ Groups : make (map [string ]* MirroringOptions ),
9386 }
9487
9588 // Read the file
@@ -115,7 +108,7 @@ func OpenMirrorMapping(path string) (*MirrorMapping, error) {
115108}
116109
117110func (m * MirrorMapping ) check () error {
118- errChan := make (chan error , 3 * (len (m .Projects )+ len (m .Groups )+ 1 ) )
111+ errChan := make (chan error , 4 * (len (m .Projects )+ len (m .Groups )) + 1 )
119112 // Check if the mapping is valid
120113 if len (m .Projects ) == 0 && len (m .Groups ) == 0 {
121114 errChan <- errors .New ("no projects or groups defined in the mapping" )
@@ -134,6 +127,11 @@ func (m *MirrorMapping) check() error {
134127 } else if strings .Count (options .DestinationPath , "/" ) < 1 {
135128 errChan <- fmt .Errorf ("invalid project destination path (must be in a namespace): %s" , options .DestinationPath )
136129 }
130+ visibilityString := strings .TrimSpace (string (options .Visibility ))
131+ if visibilityString != "" && ! checkVisibility (visibilityString ) {
132+ errChan <- fmt .Errorf ("invalid project visibility: %s" , string (options .Visibility ))
133+ options .Visibility = string (gitlab .PublicVisibility )
134+ }
137135 }
138136
139137 // Check if the groups are valid
@@ -147,11 +145,31 @@ func (m *MirrorMapping) check() error {
147145 if strings .HasPrefix (options .DestinationPath , "/" ) || strings .HasSuffix (options .DestinationPath , "/" ) {
148146 errChan <- fmt .Errorf ("invalid destination path (must not start or end with /): %s" , options .DestinationPath )
149147 }
148+ visibilityString := strings .TrimSpace (string (options .Visibility ))
149+ if visibilityString != "" && ! checkVisibility (visibilityString ) {
150+ errChan <- fmt .Errorf ("invalid group visibility: %s" , string (options .Visibility ))
151+ options .Visibility = string (gitlab .PublicVisibility )
152+ }
150153 }
151154 close (errChan )
152155 return MergeErrors (errChan , 2 )
153156}
154157
158+ func checkVisibility (visibility string ) bool {
159+ var valid bool
160+ switch visibility {
161+ case string (gitlab .PublicVisibility ):
162+ valid = true
163+ case string (gitlab .InternalVisibility ):
164+ valid = true
165+ case string (gitlab .PrivateVisibility ):
166+ valid = true
167+ default :
168+ valid = false
169+ }
170+ return valid
171+ }
172+
155173// GraphQLClient is a client for sending GraphQL requests to GitLab
156174type GraphQLClient struct {
157175 token string
0 commit comments