-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgitlab.go
More file actions
73 lines (64 loc) · 1.68 KB
/
gitlab.go
File metadata and controls
73 lines (64 loc) · 1.68 KB
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
package main
import (
"strings"
gitlab "github.com/xanzy/go-gitlab"
)
func getGitlabRepositories(
client *gitlab.Client,
gitlabProjectVisibility string, gitlabProjectMembershipType string,
ignoreFork bool,
) ([]*Repository, error) {
var repositories []*Repository
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.Projects.ListProjects(&gitlabListOptions)
if err != nil {
return nil, err
}
for _, repo := range repos {
if repo.ForkedFromProject != nil && ignoreFork {
continue
}
namespace := strings.Split(repo.PathWithNamespace, "/")[0]
cloneURL := getCloneURL(repo.WebURL, 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
}