Skip to content

Commit

Permalink
Deprecate Repositories.ListForTeam (closes #181) (#182)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
soult authored Jan 25, 2022
1 parent 5428cc4 commit ff2633c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 12 deletions.
17 changes: 5 additions & 12 deletions repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,12 @@ func (r *Repositories) ListForAccount(ro *RepositoriesOptions) (*RepositoriesRes
if err != nil {
return nil, err
}
return decodeRepositorys(repos)
return decodeRepositories(repos)
}

// Deprecated: Use ListForAccount instead
func (r *Repositories) ListForTeam(ro *RepositoriesOptions) (*RepositoriesRes, error) {
urlStr := r.c.requestUrl("/repositories/%s", ro.Owner)
if ro.Role != "" {
urlStr += "?role=" + ro.Role
}
repos, err := r.c.executeRaw("GET", urlStr, "")
if err != nil {
return nil, err
}
return decodeRepositorys(repos)
return r.ListForAccount(ro)
}

func (r *Repositories) ListPublic() (*RepositoriesRes, error) {
Expand All @@ -66,10 +59,10 @@ func (r *Repositories) ListPublic() (*RepositoriesRes, error) {
if err != nil {
return nil, err
}
return decodeRepositorys(repos)
return decodeRepositories(repos)
}

func decodeRepositorys(reposResponse interface{}) (*RepositoriesRes, error) {
func decodeRepositories(reposResponse interface{}) (*RepositoriesRes, error) {
reposResponseMap, ok := reposResponse.(map[string]interface{})
if !ok {
return nil, errors.New("Not a valid format")
Expand Down
90 changes: 90 additions & 0 deletions tests/repositories_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package tests

import (
"os"
"testing"

"github.com/ktrysmt/go-bitbucket"
)

func TestListForAccount(t *testing.T) {
user := os.Getenv("BITBUCKET_TEST_USERNAME")
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
owner := os.Getenv("BITBUCKET_TEST_OWNER")
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")

if user == "" {
t.Error("BITBUCKET_TEST_USERNAME is empty.")
}
if pass == "" {
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
}
if owner == "" {
t.Error("BITBUCKET_TEST_OWNER is empty.")
}
if repo == "" {
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
}

c := bitbucket.NewBasicAuth(user, pass)

repositories, err := c.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{
Owner: owner,
})
if err != nil {
t.Error("Unable to fetch repositories")
}

found := false
for _, r := range repositories.Items {
if r.Slug == repo {
found = true
break
}
}
if !found {
t.Error("Did not find repository in list")
}
}

func TestListForTeam(t *testing.T) {
user := os.Getenv("BITBUCKET_TEST_USERNAME")
pass := os.Getenv("BITBUCKET_TEST_PASSWORD")
owner := os.Getenv("BITBUCKET_TEST_OWNER")
repo := os.Getenv("BITBUCKET_TEST_REPOSLUG")

if user == "" {
t.Error("BITBUCKET_TEST_USERNAME is empty.")
}
if pass == "" {
t.Error("BITBUCKET_TEST_PASSWORD is empty.")
}
if owner == "" {
t.Error("BITBUCKET_TEST_OWNER is empty.")
}
if repo == "" {
t.Error("BITBUCKET_TEST_REPOSLUG is empty.")
}

c := bitbucket.NewBasicAuth(user, pass)

//goland:noinspection GoDeprecation
repositories, err := c.Repositories.ListForTeam(&bitbucket.RepositoriesOptions{

Owner: owner,
})
if err != nil {
t.Error("Unable to fetch repositories")
}

found := false
for _, r := range repositories.Items {
if r.Slug == repo {
found = true
break
}
}
if !found {
t.Error("Did not find repository in list")
}
}

0 comments on commit ff2633c

Please sign in to comment.