-
Notifications
You must be signed in to change notification settings - Fork 33
/
gitlab.go
77 lines (66 loc) · 1.85 KB
/
gitlab.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"log"
"strings"
gitlab "github.com/xanzy/go-gitlab"
)
func getGitlabRepositories(
client interface{},
service string, githubRepoType string, githubNamespaceWhitelist []string,
gitlabProjectVisibility string, gitlabProjectMembershipType string,
ignoreFork bool,
) ([]*Repository, error) {
if client == nil {
log.Fatalf("Couldn't acquire a client to talk to %s", service)
}
var repositories []*Repository
var cloneURL string
var visibility gitlab.VisibilityValue
var boolTrue bool = true
gitlabListOptions := gitlab.ListProjectsOptions{}
switch gitlabProjectMembershipType {
case "owner":
gitlabListOptions.Owned = &boolTrue
case "member":
gitlabListOptions.Membership = &boolTrue
case "starred":
gitlabListOptions.Starred = &boolTrue
case "all":
gitlabListOptions.Owned = &boolTrue
gitlabListOptions.Membership = &boolTrue
gitlabListOptions.Starred = &boolTrue
}
if gitlabProjectVisibility != "all" {
switch gitlabProjectVisibility {
case "public":
visibility = gitlab.PublicVisibility
case "private":
visibility = gitlab.PrivateVisibility
case "internal":
fallthrough
case "default":
visibility = gitlab.InternalVisibility
}
gitlabListOptions.Visibility = &visibility
}
for {
repos, resp, err := client.(*gitlab.Client).Projects.ListProjects(&gitlabListOptions)
if err != nil {
return nil, err
}
for _, repo := range repos {
namespace := strings.Split(repo.PathWithNamespace, "/")[0]
if useHTTPSClone != nil && *useHTTPSClone {
cloneURL = repo.WebURL
} else {
cloneURL = repo.SSHURLToRepo
}
repositories = append(repositories, &Repository{CloneURL: cloneURL, Name: repo.Name, Namespace: namespace, Private: repo.Visibility == "private"})
}
if resp.NextPage == 0 {
break
}
gitlabListOptions.ListOptions.Page = resp.NextPage
}
return repositories, nil
}