1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2024-11-28 08:39:03 +02:00

Added the method to get the profile of the currently logged in user.

https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-myself-get

Signed-off-by: Eugene Dzhurinsky <jdevelop@gmail.com>
This commit is contained in:
Eugene Dzhurinsky 2018-06-28 18:44:35 -04:00
parent 37f2d5b759
commit b01e0251ce
2 changed files with 45 additions and 0 deletions

17
user.go
View File

@ -99,6 +99,23 @@ func (s *UserService) GetGroups(username string) (*[]UserGroup, *Response, error
return userGroups, resp, nil
}
// Get information about the current logged-in user
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-myself-get
func (s *UserService) GetSelf() (*User, *Response, error) {
const apiEndpoint = "rest/api/2/myself"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
var user User
resp, err := s.client.Do(req, &user)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return &user, resp, nil
}
// Find searches for user info from JIRA:
// It can find users by email, username or name
//

View File

@ -74,6 +74,34 @@ func TestUserService_GetGroups(t *testing.T) {
}
}
func TestUserService_GetSelf(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/myself", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/myself")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","key":"fred",
"name":"fred","emailAddress":"fred@example.com","avatarUrls":{"48x48":"http://www.example.com/jira/secure/useravatar?size=large&ownerId=fred",
"24x24":"http://www.example.com/jira/secure/useravatar?size=small&ownerId=fred","16x16":"http://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred",
"32x32":"http://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred"},"displayName":"Fred F. User","active":true,"timeZone":"Australia/Sydney","groups":{"size":3,"items":[
{"name":"jira-user","self":"http://www.example.com/jira/rest/api/2/group?groupname=jira-user"},{"name":"jira-admin",
"self":"http://www.example.com/jira/rest/api/2/group?groupname=jira-admin"},{"name":"important","self":"http://www.example.com/jira/rest/api/2/group?groupname=important"
}]},"applicationRoles":{"size":1,"items":[]},"expand":"groups,applicationRoles"}`)
})
if user, _, err := testClient.User.GetSelf(); err != nil {
t.Errorf("Error given: %s", err)
} else if user == nil {
t.Error("Expected user groups. []UserGroup is nil")
} else if user.Name != "fred" ||
!user.Active ||
user.DisplayName != "Fred F. User" {
t.Errorf("User JSON deserialized incorrectly")
}
}
func TestUserService_Find_Success(t *testing.T) {
setup()
defer teardown()