1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-07-17 01:12:24 +02:00

Add some APIs on a JIRA group

This commit is contained in:
b4b4r07
2017-11-28 11:56:49 +09:00
parent 9f1498acb6
commit fbd056e79a
3 changed files with 106 additions and 0 deletions

View File

@ -20,6 +20,23 @@ type groupMembersResult struct {
Members []GroupMember `json:"values"`
}
// Group represents a JIRA group
type Group struct {
ID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Properties groupProperties `json:"properties"`
AdditionalProperties bool `json:"additionalProperties"`
}
type groupProperties struct {
Name groupPropertiesName `json:"name"`
}
type groupPropertiesName struct {
Type string `json:"type"`
}
// GroupMember reflects a single member of a group
type GroupMember struct {
Self string `json:"self,omitempty"`
@ -51,3 +68,50 @@ func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
return group.Members, resp, nil
}
// Add adds user to group
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup
func (s *GroupService) Add(groupname string, username string) (*Group, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/group/user?groupname=%s", groupname)
var user struct {
Name string `json:"name"`
}
user.Name = username
req, err := s.client.NewRequest("POST", apiEndpoint, &user)
if err != nil {
return nil, nil, err
}
responseGroup := new(Group)
resp, err := s.client.Do(req, responseGroup)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return responseGroup, resp, nil
}
// Remove removes user from group
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-removeUserFromGroup
func (s *GroupService) Remove(groupname string, username string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/group/user?groupname=%s&username=%s", groupname, username)
// var user struct {
// Name string `json:"name"`
// }
// user.Name = username
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraError(resp, err)
return resp, jerr
}
return resp, nil
}