Skip to content

Commit 87ce546

Browse files
author
Samuel Contesse
authored
Pull request reviewers as uuid and strong user type (#89)
* Change username to uuid due to API deprecation https://developer.atlassian.com/cloud/bitbucket/bitbucket-api-changes-gdpr/#removal-of-usernames-from-user-referencing-apis * Add typings to the user profile resource
1 parent b05e677 commit 87ce546

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

bitbucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type users interface {
88
}
99

1010
type user interface {
11-
Profile() (interface{}, error)
11+
Profile() (*User, error)
1212
Emails() (interface{}, error)
1313
}
1414

pullrequests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func (p *PullRequests) buildPullRequestBody(po *PullRequestsOptions) string {
130130

131131
if n := len(po.Reviewers); n > 0 {
132132
body["reviewers"] = make([]map[string]string, n)
133-
for i, user := range po.Reviewers {
134-
body["reviewers"].([]map[string]string)[i] = map[string]string{"username": user}
133+
for i, uuid := range po.Reviewers {
134+
body["reviewers"].([]map[string]string)[i] = map[string]string{"uuid": uuid}
135135
}
136136
}
137137

user.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
package bitbucket
22

3+
import (
4+
"github.com/mitchellh/mapstructure"
5+
)
6+
37
// User is the sub struct of Client
8+
// Reference: https://developer.atlassian.com/bitbucket/api/2/reference/resource/user
49
type User struct {
5-
c *Client
10+
c *Client
11+
Uuid string
12+
Username string
13+
Nickname string
14+
Website string
15+
AccountStatus string `mapstructure:"account_status"`
16+
DisplayName string `mapstructure:"display_name"`
17+
CreatedOn string `mapstructure:"created_on"`
18+
Has2faEnabled bool `mapstructure:"has_2fa_enabled"`
19+
Links map[string]interface{}
620
}
721

822
// Profile is getting the user data
9-
func (u *User) Profile() (interface{}, error) {
23+
func (u *User) Profile() (*User, error) {
1024
urlStr := u.c.GetApiBaseURL() + "/user/"
11-
return u.c.execute("GET", urlStr, "")
25+
response, err := u.c.execute("GET", urlStr, "")
26+
if err != nil {
27+
return nil, err
28+
}
29+
return decodeUser(response)
1230
}
1331

1432
// Emails is getting user's emails
1533
func (u *User) Emails() (interface{}, error) {
1634
urlStr := u.c.GetApiBaseURL() + "/user/emails"
1735
return u.c.execute("GET", urlStr, "")
1836
}
37+
38+
func decodeUser(userResponse interface{}) (*User, error) {
39+
userMap := userResponse.(map[string]interface{})
40+
41+
if userMap["type"] == "error" {
42+
return nil, DecodeError(userMap)
43+
}
44+
45+
var user = new(User)
46+
err := mapstructure.Decode(userMap, user)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
return user, nil
52+
}

0 commit comments

Comments
 (0)