Skip to content

Commit afbef33

Browse files
authored
fix Clone Links (#46)
1 parent 0c1f6dc commit afbef33

File tree

3 files changed

+61
-53
lines changed

3 files changed

+61
-53
lines changed

bitbucket/bitbucket-accessors.go

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

bitbucket/repositories.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,9 @@ type RepositoryMainBranch struct {
4747
Name *string `json:"name,omitempty"`
4848
}
4949

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 {
50+
// GetHTTPSCloneURL get the HTTPS clone url. Returns empty string if not found.
51+
func (rl *RepositoryLinks) GetHTTPSCloneURL() string {
52+
for _, link := range rl.Clone {
5853
if link.GetName() == "https" {
5954
return link.GetHRef()
6055
}
@@ -63,9 +58,9 @@ func (rcl *RepositoryCloneLinks) GetHTTPS() string {
6358
return ""
6459
}
6560

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 {
61+
// GetSSHCloneURL get the SSH clone url. Returns empty string if not found.
62+
func (rl *RepositoryLinks) GetSSHCloneURL() string {
63+
for _, link := range rl.Clone {
6964
if link.GetName() == "ssh" {
7065
return link.GetHRef()
7166
}
@@ -76,18 +71,18 @@ func (rcl *RepositoryCloneLinks) GetSSH() string {
7671

7772
// RepositoryLinks represents the "links" object in a Bitbucket repository.
7873
type RepositoryLinks struct {
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"`
74+
Clone []*Link `json:"clone,omitempty"`
75+
Watchers *Link `json:"watchers,omitempty"`
76+
Branches *Link `json:"branches,omitempty"`
77+
Tags *Link `json:"tags,omitempty"`
78+
Commits *Link `json:"commits,omitempty"`
79+
Downloads *Link `json:"downloads,omitempty"`
80+
Source *Link `json:"source,omitempty"`
81+
HTML *Link `json:"html,omitempty"`
82+
Avatar *Link `json:"avatar,omitempty"`
83+
Forks *Link `json:"forks,omitempty"`
84+
Self *Link `json:"self,omitempty"`
85+
PullRequests *Link `json:"pull_requests,omitempty"`
9186
}
9287

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

bitbucket/repositories_test.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,45 @@ func TestRepositoryCloneLinks_GetLinks(t *testing.T) {
1111
sshName := "ssh"
1212
sshHREF := "www.this.isthe.ssh.link.com"
1313

14-
cloneLinks := &RepositoryCloneLinks{Values: []*Link{
15-
{
16-
Name: &httpName,
17-
HRef: &httpHREF,
14+
cloneLinks := &RepositoryLinks{
15+
Clone: []*Link{
16+
{
17+
Name: &httpName,
18+
HRef: &httpHREF,
19+
},
20+
{
21+
Name: &sshName,
22+
HRef: &sshHREF,
23+
},
1824
},
19-
{
20-
Name: &sshName,
21-
HRef: &sshHREF,
22-
},
23-
}}
25+
}
2426

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+
assert.Equal(t, "www.this.isthe.https.link.com", cloneLinks.GetHTTPSCloneURL())
28+
assert.Equal(t, "www.this.isthe.ssh.link.com", cloneLinks.GetSSHCloneURL())
2729
}
2830

2931
func TestRepositoryCloneLinks_GetLinks_Missing(t *testing.T) {
3032
httpName := "https"
3133
httpHREF := "www.this.isthe.https.link.com"
3234

33-
cloneLinks := &RepositoryCloneLinks{Values: []*Link{
34-
{
35-
Name: &httpName,
36-
HRef: &httpHREF,
35+
cloneLinks := &RepositoryLinks{
36+
Clone: []*Link{
37+
{
38+
Name: &httpName,
39+
HRef: &httpHREF,
40+
},
3741
},
38-
}}
42+
}
43+
44+
assert.Equal(t, "www.this.isthe.https.link.com", cloneLinks.GetHTTPSCloneURL())
45+
assert.Equal(t, "", cloneLinks.GetSSHCloneURL())
46+
}
47+
48+
func TestRepositoryCloneLinks_GetLinks_None(t *testing.T) {
49+
cloneLinks := &RepositoryLinks{
50+
Clone: []*Link{},
51+
}
3952

40-
assert.Equal(t, "www.this.isthe.https.link.com", cloneLinks.GetHTTPS())
41-
assert.Equal(t, "", cloneLinks.GetSSH())
53+
assert.Equal(t, "", cloneLinks.GetHTTPSCloneURL())
54+
assert.Equal(t, "", cloneLinks.GetSSHCloneURL())
4255
}

0 commit comments

Comments
 (0)