-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbitbucket.go
More file actions
70 lines (56 loc) · 1.4 KB
/
bitbucket.go
File metadata and controls
70 lines (56 loc) · 1.4 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
package main
import (
"strings"
bitbucket "github.com/ktrysmt/go-bitbucket"
)
func getBitbucketRepositories(
client *bitbucket.Client,
ignoreFork bool,
) ([]*Repository, error) {
var repositories []*Repository
resp, err := client.Workspaces.List()
if err != nil {
return nil, err
}
for _, workspace := range resp.Workspaces {
options := &bitbucket.RepositoriesOptions{Owner: workspace.Slug}
resp, err := client.Repositories.ListForAccount(options)
if err != nil {
return nil, err
}
for _, repo := range resp.Items {
if repo.Parent != nil && ignoreFork {
continue
}
namespace := strings.Split(repo.Full_name, "/")[0]
httpsURL, sshURL := extractBitbucketCloneURLs(repo.Links)
cloneURL := getCloneURL(httpsURL, sshURL)
repositories = append(repositories, &Repository{
CloneURL: cloneURL,
Name: repo.Slug,
Namespace: namespace,
Private: repo.Is_private,
})
}
}
return repositories, nil
}
func extractBitbucketCloneURLs(links map[string]interface{}) (httpsURL, sshURL string) {
linkmaps, ok := links["clone"].([]interface{})
if !ok {
return "", ""
}
for _, linkmaps := range linkmaps {
linkmap, ok := linkmaps.(map[string]interface{})
if !ok {
continue
}
if linkmap["name"] == "https" {
httpsURL = linkmap["href"].(string)
}
if linkmap["name"] == "ssh" {
sshURL = linkmap["href"].(string)
}
}
return httpsURL, sshURL
}