Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type users interface {
}

type user interface {
Profile() (interface{}, error)
Profile() (*User, error)
Emails() (interface{}, error)
}

Expand Down
4 changes: 2 additions & 2 deletions pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func (p *PullRequests) buildPullRequestBody(po *PullRequestsOptions) string {

if n := len(po.Reviewers); n > 0 {
body["reviewers"] = make([]map[string]string, n)
for i, user := range po.Reviewers {
body["reviewers"].([]map[string]string)[i] = map[string]string{"username": user}
for i, uuid := range po.Reviewers {
body["reviewers"].([]map[string]string)[i] = map[string]string{"uuid": uuid}
}
}

Expand Down
40 changes: 37 additions & 3 deletions user.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
package bitbucket

import (
"github.com/mitchellh/mapstructure"
)

// User is the sub struct of Client
// Reference: https://developer.atlassian.com/bitbucket/api/2/reference/resource/user
type User struct {
c *Client
c *Client
Uuid string
Username string
Nickname string
Website string
AccountStatus string `mapstructure:"account_status"`
DisplayName string `mapstructure:"display_name"`
CreatedOn string `mapstructure:"created_on"`
Has2faEnabled bool `mapstructure:"has_2fa_enabled"`
Links map[string]interface{}
}

// Profile is getting the user data
func (u *User) Profile() (interface{}, error) {
func (u *User) Profile() (*User, error) {
urlStr := u.c.GetApiBaseURL() + "/user/"
return u.c.execute("GET", urlStr, "")
response, err := u.c.execute("GET", urlStr, "")
if err != nil {
return nil, err
}
return decodeUser(response)
}

// Emails is getting user's emails
func (u *User) Emails() (interface{}, error) {
urlStr := u.c.GetApiBaseURL() + "/user/emails"
return u.c.execute("GET", urlStr, "")
}

func decodeUser(userResponse interface{}) (*User, error) {
userMap := userResponse.(map[string]interface{})

if userMap["type"] == "error" {
return nil, DecodeError(userMap)
}

var user = new(User)
err := mapstructure.Decode(userMap, user)
if err != nil {
return nil, err
}

return user, nil
}