Skip to content

Commit

Permalink
feat: ✨ Expose User object on access tokens to allow access to user name
Browse files Browse the repository at this point in the history
  • Loading branch information
langecode committed Jan 10, 2023
1 parent e6059be commit e37c6b9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 7 additions & 0 deletions bitbucket/access_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ type AccessToken struct {
Expire *DateTime `json:"expiryDate,omitempty"`
ExpireDays int `json:"expiryDays,omitempty"`
Token string `json:"token,omitempty"`
User *User `json:"user,omitempty"`
}

type User struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
}
1 change: 1 addition & 0 deletions bitbucket/access_tokens_repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestCreateRepositoryToken(t *testing.T) {
token, _, err := client.AccessTokens.CreateRepositoryToken(ctx, "PRJ", "repo", in)
assert.NoError(t, err)
assert.Equal(t, "BBDC-xxxx", token.Token)
assert.Equal(t, "access-token-user/2/1405", token.User.Name)
}

func TestDeleteRepositoryToken(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ type service struct {

type Page struct {
// The following properties support the paged APIs.
Size int
Limit int
Size uint
Limit uint
LastPage bool
Start int
Start uint
// The next page start should be used with the ListOptions struct.
NextPageStart int
NextPageStart uint
}

// Paged defines interface to be supported by responses from Paged APIs
Expand All @@ -55,11 +55,11 @@ type Paged interface {

// ListResponse defines the common properties of a list response
type ListResponse struct {
Size int `json:"size"`
Limit int `json:"limit"`
Size uint `json:"size"`
Limit uint `json:"limit"`
LastPage bool `json:"isLastPage"`
Start int `json:"start"`
NextPageStart int `json:"nextPageStart"`
Start uint `json:"start"`
NextPageStart uint `json:"nextPageStart"`
}

func (r *ListResponse) Current() *Page {
Expand Down
2 changes: 1 addition & 1 deletion bitbucket/projects_repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestListProjectRepositories(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, repos, 3)
assert.False(t, resp.LastPage)
assert.Equal(t, 25, resp.Page.NextPageStart)
assert.Equal(t, uint(25), resp.Page.NextPageStart)
}

func TestListProjectRepositoriesNextPage(t *testing.T) {
Expand Down

0 comments on commit e37c6b9

Please sign in to comment.