Skip to content

Commit ff2633c

Browse files
authored
Deprecate Repositories.ListForTeam (closes #181) (#182)
* Add tests for Repositories.GetFor(Account|Team) * Deprecate Repositories.GetForTeam (closes #181) Make Repositories.GetForTeam an alias to Repositories.GetForAccount, and mark the former as deprecated, since they both do the same.
1 parent 5428cc4 commit ff2633c

File tree

2 files changed

+95
-12
lines changed

2 files changed

+95
-12
lines changed

repositories.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,12 @@ func (r *Repositories) ListForAccount(ro *RepositoriesOptions) (*RepositoriesRes
4545
if err != nil {
4646
return nil, err
4747
}
48-
return decodeRepositorys(repos)
48+
return decodeRepositories(repos)
4949
}
5050

51+
// Deprecated: Use ListForAccount instead
5152
func (r *Repositories) ListForTeam(ro *RepositoriesOptions) (*RepositoriesRes, error) {
52-
urlStr := r.c.requestUrl("/repositories/%s", ro.Owner)
53-
if ro.Role != "" {
54-
urlStr += "?role=" + ro.Role
55-
}
56-
repos, err := r.c.executeRaw("GET", urlStr, "")
57-
if err != nil {
58-
return nil, err
59-
}
60-
return decodeRepositorys(repos)
53+
return r.ListForAccount(ro)
6154
}
6255

6356
func (r *Repositories) ListPublic() (*RepositoriesRes, error) {
@@ -66,10 +59,10 @@ func (r *Repositories) ListPublic() (*RepositoriesRes, error) {
6659
if err != nil {
6760
return nil, err
6861
}
69-
return decodeRepositorys(repos)
62+
return decodeRepositories(repos)
7063
}
7164

72-
func decodeRepositorys(reposResponse interface{}) (*RepositoriesRes, error) {
65+
func decodeRepositories(reposResponse interface{}) (*RepositoriesRes, error) {
7366
reposResponseMap, ok := reposResponse.(map[string]interface{})
7467
if !ok {
7568
return nil, errors.New("Not a valid format")

tests/repositories_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package tests
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/ktrysmt/go-bitbucket"
8+
)
9+
10+
func TestListForAccount(t *testing.T) {
11+
user := os.Getenv("BITBUCKET_TEST_USERNAME")
12+
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
13+
owner := os.Getenv("BITBUCKET_TEST_OWNER")
14+
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")
15+
16+
if user == "" {
17+
t.Error("BITBUCKET_TEST_USERNAME is empty.")
18+
}
19+
if pass == "" {
20+
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
21+
}
22+
if owner == "" {
23+
t.Error("BITBUCKET_TEST_OWNER is empty.")
24+
}
25+
if repo == "" {
26+
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
27+
}
28+
29+
c := bitbucket.NewBasicAuth(user, pass)
30+
31+
repositories, err := c.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{
32+
Owner: owner,
33+
})
34+
if err != nil {
35+
t.Error("Unable to fetch repositories")
36+
}
37+
38+
found := false
39+
for _, r := range repositories.Items {
40+
if r.Slug == repo {
41+
found = true
42+
break
43+
}
44+
}
45+
if !found {
46+
t.Error("Did not find repository in list")
47+
}
48+
}
49+
50+
func TestListForTeam(t *testing.T) {
51+
user := os.Getenv("BITBUCKET_TEST_USERNAME")
52+
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
53+
owner := os.Getenv("BITBUCKET_TEST_OWNER")
54+
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")
55+
56+
if user == "" {
57+
t.Error("BITBUCKET_TEST_USERNAME is empty.")
58+
}
59+
if pass == "" {
60+
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
61+
}
62+
if owner == "" {
63+
t.Error("BITBUCKET_TEST_OWNER is empty.")
64+
}
65+
if repo == "" {
66+
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
67+
}
68+
69+
c := bitbucket.NewBasicAuth(user, pass)
70+
71+
//goland:noinspection GoDeprecation
72+
repositories, err := c.Repositories.ListForTeam(&bitbucket.RepositoriesOptions{
73+
74+
Owner: owner,
75+
})
76+
if err != nil {
77+
t.Error("Unable to fetch repositories")
78+
}
79+
80+
found := false
81+
for _, r := range repositories.Items {
82+
if r.Slug == repo {
83+
found = true
84+
break
85+
}
86+
}
87+
if !found {
88+
t.Error("Did not find repository in list")
89+
}
90+
}

0 commit comments

Comments
 (0)