@@ -37,7 +37,11 @@ type Repository struct {
37
37
Private bool
38
38
}
39
39
40
- func getRepositories (client interface {}, service string , githubRepoType string , gitlabRepoVisibility string , gitlabProjectType string , ignoreFork bool ) ([]* Repository , error ) {
40
+ func getRepositories (client interface {},
41
+ service string , githubRepoType string ,
42
+ gitlabProjectVisibility string , gitlabProjectMembershipType string ,
43
+ ignoreFork bool ,
44
+ ) ([]* Repository , error ) {
41
45
42
46
if client == nil {
43
47
log .Fatalf ("Couldn't acquire a client to talk to %s" , service )
@@ -104,25 +108,26 @@ func getRepositories(client interface{}, service string, githubRepoType string,
104
108
105
109
if service == "gitlab" {
106
110
var visibility gitlab.VisibilityValue
107
- var options gitlab.ListProjectsOptions
108
-
109
- var owned bool
110
- var memberOf bool
111
-
112
- if gitlabProjectType == "owner" {
113
- owned = true
114
- }
115
- if gitlabProjectType == "member" {
116
- memberOf = true
111
+ var boolTrue bool = true
112
+
113
+ gitlabListOptions := gitlab.ListProjectsOptions {}
114
+
115
+ switch gitlabProjectMembershipType {
116
+
117
+ case "owner" :
118
+ gitlabListOptions .Owned = & boolTrue
119
+ case "member" :
120
+ gitlabListOptions .Membership = & boolTrue
121
+ case "starred" :
122
+ gitlabListOptions .Starred = & boolTrue
123
+ case "all" :
124
+ gitlabListOptions .Owned = & boolTrue
125
+ gitlabListOptions .Membership = & boolTrue
126
+ gitlabListOptions .Starred = & boolTrue
117
127
}
118
128
119
- if gitlabProjectType == "all" {
120
- owned = true
121
- memberOf = true
122
- }
123
-
124
- if gitlabRepoVisibility != "all" {
125
- switch gitlabRepoVisibility {
129
+ if gitlabProjectVisibility != "all" {
130
+ switch gitlabProjectVisibility {
126
131
case "public" :
127
132
visibility = gitlab .PublicVisibility
128
133
case "private" :
@@ -132,30 +137,27 @@ func getRepositories(client interface{}, service string, githubRepoType string,
132
137
case "default" :
133
138
visibility = gitlab .InternalVisibility
134
139
}
135
- options = gitlab.ListProjectsOptions {Visibility : & visibility , Membership : & memberOf , Owned : & owned }
136
- } else {
137
- options = gitlab.ListProjectsOptions {Membership : & memberOf , Owned : & owned }
140
+ gitlabListOptions .Visibility = & visibility
138
141
}
139
142
140
143
for {
141
- repos , resp , err := client .(* gitlab.Client ).Projects .ListProjects (& options )
142
- if err == nil {
143
- for _ , repo := range repos {
144
- namespace := strings .Split (repo .PathWithNamespace , "/" )[0 ]
145
- if useHTTPSClone != nil && * useHTTPSClone {
146
- cloneURL = repo .WebURL
147
- } else {
148
- cloneURL = repo .SSHURLToRepo
149
- }
150
- repositories = append (repositories , & Repository {CloneURL : cloneURL , Name : repo .Name , Namespace : namespace , Private : repo .Public })
151
- }
152
- } else {
144
+ repos , resp , err := client .(* gitlab.Client ).Projects .ListProjects (& gitlabListOptions )
145
+ if err != nil {
153
146
return nil , err
154
147
}
148
+ for _ , repo := range repos {
149
+ namespace := strings .Split (repo .PathWithNamespace , "/" )[0 ]
150
+ if useHTTPSClone != nil && * useHTTPSClone {
151
+ cloneURL = repo .WebURL
152
+ } else {
153
+ cloneURL = repo .SSHURLToRepo
154
+ }
155
+ repositories = append (repositories , & Repository {CloneURL : cloneURL , Name : repo .Name , Namespace : namespace , Private : repo .Public })
156
+ }
155
157
if resp .NextPage == 0 {
156
158
break
157
159
}
158
- options .ListOptions .Page = resp .NextPage
160
+ gitlabListOptions .ListOptions .Page = resp .NextPage
159
161
}
160
162
}
161
163
@@ -207,6 +209,5 @@ func getRepositories(client interface{}, service string, githubRepoType string,
207
209
}
208
210
}
209
211
}
210
-
211
212
return repositories , nil
212
213
}
0 commit comments