-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbitbucket.go
71 lines (55 loc) · 1.56 KB
/
bitbucket.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
package main
import (
"log"
"strings"
bitbucket "github.com/ktrysmt/go-bitbucket"
)
func getBitbucketRepositories(
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
resp, err := client.(*bitbucket.Client).Workspaces.List()
if err != nil {
return nil, err
}
for _, workspace := range resp.Workspaces {
options := &bitbucket.RepositoriesOptions{Owner: workspace.Slug}
resp, err := client.(*bitbucket.Client).Repositories.ListForAccount(options)
if err != nil {
return nil, err
}
for _, repo := range resp.Items {
namespace := strings.Split(repo.Full_name, "/")[0]
linkmaps, ok := repo.Links["clone"].([]interface{})
var httpsURL string
var sshURL string
if ok {
for _, linkmaps := range linkmaps {
linkmap, ok := linkmaps.(map[string]interface{})
if ok {
if linkmap["name"] == "https" {
httpsURL = linkmap["href"].(string)
}
if linkmap["name"] == "ssh" {
sshURL = linkmap["href"].(string)
}
}
}
}
if useHTTPSClone != nil && *useHTTPSClone {
cloneURL = httpsURL
} else {
cloneURL = sshURL
}
repositories = append(repositories, &Repository{CloneURL: cloneURL, Name: repo.Slug, Namespace: namespace, Private: repo.Is_private})
}
}
return repositories, nil
}