Skip to content

Commit 0c1f6dc

Browse files
authored
- Redefine Clone field on RepositoryLinks struct (#45)
- Update getters - Functions to get SSH/HTTPS clone links
1 parent 4c4c5c2 commit 0c1f6dc

File tree

4 files changed

+104
-39
lines changed

4 files changed

+104
-39
lines changed

bitbucket/bitbucket-accessors.go

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bitbucket/bitbucket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type service struct {
8787

8888
// Link represents a single link object from Bitbucket object links.
8989
type Link struct {
90+
Name *string `json:"name,omitempty"`
9091
HRef *string `json:"href,omitempty"`
9192
}
9293

bitbucket/repositories.go

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Repositories struct {
1919

2020
// Repository represents a Bitbucket repository.
2121
type Repository struct {
22+
UUID *string `json:"uuid,omitempty"`
2223
SCM *string `json:"scm,omitempty"`
2324
Website *string `json:"page,omitempty"`
2425
HasIssues *bool `json:"has_issues,omitempty"`
@@ -46,26 +47,47 @@ type RepositoryMainBranch struct {
4647
Name *string `json:"name,omitempty"`
4748
}
4849

49-
// RepositoryCloneLink represents the specific clone related links in a Bitbucket repository.
50-
type RepositoryCloneLink struct {
51-
HRef *string `json:"href,omitempty"`
52-
Name *string `json:"name,omitempty"`
50+
// RepositoryCloneLinks represents a collection of repository clone links.
51+
type RepositoryCloneLinks struct {
52+
Values []*Link
53+
}
54+
55+
// GetHTTPS get the HTTPS clone link. Returns empty string if not found.
56+
func (rcl *RepositoryCloneLinks) GetHTTPS() string {
57+
for _, link := range rcl.Values {
58+
if link.GetName() == "https" {
59+
return link.GetHRef()
60+
}
61+
}
62+
63+
return ""
64+
}
65+
66+
// GetSSH get the SSH clone link. Returns empty string if not found.
67+
func (rcl *RepositoryCloneLinks) GetSSH() string {
68+
for _, link := range rcl.Values {
69+
if link.GetName() == "ssh" {
70+
return link.GetHRef()
71+
}
72+
}
73+
74+
return ""
5375
}
5476

5577
// RepositoryLinks represents the "links" object in a Bitbucket repository.
5678
type RepositoryLinks struct {
57-
Clone []*RepositoryCloneLink `json:"clone,omitempty"`
58-
Watchers *Link `json:"watchers,omitempty"`
59-
Branches *Link `json:"branches,omitempty"`
60-
Tags *Link `json:"tags,omitempty"`
61-
Commits *Link `json:"commits,omitempty"`
62-
Downloads *Link `json:"downloads,omitempty"`
63-
Source *Link `json:"source,omitempty"`
64-
HTML *Link `json:"html,omitempty"`
65-
Avatar *Link `json:"avatar,omitempty"`
66-
Forks *Link `json:"forks,omitempty"`
67-
Self *Link `json:"self,omitempty"`
68-
PullRequests *Link `json:"pull_requests,omitempty"`
79+
Clone RepositoryCloneLinks `json:"clone,omitempty"`
80+
Watchers *Link `json:"watchers,omitempty"`
81+
Branches *Link `json:"branches,omitempty"`
82+
Tags *Link `json:"tags,omitempty"`
83+
Commits *Link `json:"commits,omitempty"`
84+
Downloads *Link `json:"downloads,omitempty"`
85+
Source *Link `json:"source,omitempty"`
86+
HTML *Link `json:"html,omitempty"`
87+
Avatar *Link `json:"avatar,omitempty"`
88+
Forks *Link `json:"forks,omitempty"`
89+
Self *Link `json:"self,omitempty"`
90+
PullRequests *Link `json:"pull_requests,omitempty"`
6991
}
7092

7193
// RepositoryListQueryParams represents the filters and query parameters available when listing repositories.

bitbucket/repositories_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package bitbucket
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestRepositoryCloneLinks_GetLinks(t *testing.T) {
9+
httpName := "https"
10+
httpHREF := "www.this.isthe.https.link.com"
11+
sshName := "ssh"
12+
sshHREF := "www.this.isthe.ssh.link.com"
13+
14+
cloneLinks := &RepositoryCloneLinks{Values: []*Link{
15+
{
16+
Name: &httpName,
17+
HRef: &httpHREF,
18+
},
19+
{
20+
Name: &sshName,
21+
HRef: &sshHREF,
22+
},
23+
}}
24+
25+
assert.Equal(t, "www.this.isthe.https.link.com", cloneLinks.GetHTTPS())
26+
assert.Equal(t, "www.this.isthe.ssh.link.com", cloneLinks.GetSSH())
27+
}
28+
29+
func TestRepositoryCloneLinks_GetLinks_Missing(t *testing.T) {
30+
httpName := "https"
31+
httpHREF := "www.this.isthe.https.link.com"
32+
33+
cloneLinks := &RepositoryCloneLinks{Values: []*Link{
34+
{
35+
Name: &httpName,
36+
HRef: &httpHREF,
37+
},
38+
}}
39+
40+
assert.Equal(t, "www.this.isthe.https.link.com", cloneLinks.GetHTTPS())
41+
assert.Equal(t, "", cloneLinks.GetSSH())
42+
}

0 commit comments

Comments
 (0)