Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: update Add/Remove due to 'username' argument being deprecated #414

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 22 additions & 22 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type groupMembersResult struct {

// 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"`
Name string `json:"name,omitempty" structs:"name,omitempty"`
Self string `json:"self,omitempty" structs:"self,omitempty"`
GroupMembers GroupMembers `json:"users,omitempty" structs:"users,omitempty"`
Expand string `json:"expand,omitempty" structs:"expand,omitempty"`
}

type groupProperties struct {
Name groupPropertiesName `json:"name"`
}

type groupPropertiesName struct {
Type string `json:"type"`
// GroupMembers represent members in a Jira group
type GroupMembers struct {
Size int `json:"size,omitempty" structs:"size,omitempty"`
Items []GroupMember `json:"items,omitempty" structs:"items,omitempty"`
MaxResults int `json:"max-results,omitempty" structs:"max-results.omitempty"`
StartIndex int `json:"start-index,omitempty" structs:"start-index,omitempty"`
EndIndex int `json:"end-index,omitempty" structs:"end-index,omitempty"`
}

// GroupMember reflects a single member of a group
Expand Down Expand Up @@ -125,13 +125,13 @@ func (s *GroupService) GetWithOptions(name string, options *GroupSearchOptions)

// AddWithContext adds user to group
//
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup
func (s *GroupService) AddWithContext(ctx context.Context, groupname string, username string) (*Group, *Response, error) {
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-groups/#api-rest-api-2-group-user-post
func (s *GroupService) AddWithContext(ctx context.Context, groupname string, accountID string) (*Group, *Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s", groupname)
var user struct {
Name string `json:"name"`
AccountID string `json:"accountId"`
}
user.Name = username
user.AccountID = accountID
req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndpoint, &user)
if err != nil {
return nil, nil, err
Expand All @@ -148,15 +148,15 @@ func (s *GroupService) AddWithContext(ctx context.Context, groupname string, use
}

// Add wraps AddWithContext using the background context.
func (s *GroupService) Add(groupname string, username string) (*Group, *Response, error) {
return s.AddWithContext(context.Background(), groupname, username)
func (s *GroupService) Add(groupname string, accountID string) (*Group, *Response, error) {
return s.AddWithContext(context.Background(), groupname, accountID)
}

// RemoveWithContext removes user from group
//
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-removeUserFromGroup
func (s *GroupService) RemoveWithContext(ctx context.Context, groupname string, username string) (*Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s&username=%s", groupname, username)
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-groups/#api-rest-api-2-group-user-delete
func (s *GroupService) RemoveWithContext(ctx context.Context, groupname string, accountID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s&accountId=%s", groupname, accountID)
req, err := s.client.NewRequestWithContext(ctx, "DELETE", apiEndpoint, nil)
if err != nil {
return nil, err
Expand All @@ -172,6 +172,6 @@ func (s *GroupService) RemoveWithContext(ctx context.Context, groupname string,
}

// Remove wraps RemoveWithContext using the background context.
func (s *GroupService) Remove(groupname string, username string) (*Response, error) {
return s.RemoveWithContext(context.Background(), groupname, username)
func (s *GroupService) Remove(groupname string, accountID string) (*Response, error) {
return s.RemoveWithContext(context.Background(), groupname, accountID)
}
4 changes: 2 additions & 2 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestGroupService_Add(t *testing.T) {
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
})

if group, _, err := testClient.Group.Add("default", "theodore"); err != nil {
if group, _, err := testClient.Group.Add("default", "000000000000000000000000"); err != nil {
t.Errorf("Error given: %s", err)
} else if group == nil {
t.Error("Expected group. Group is nil")
Expand All @@ -105,7 +105,7 @@ func TestGroupService_Remove(t *testing.T) {
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
})

if _, err := testClient.Group.Remove("default", "theodore"); err != nil {
if _, err := testClient.Group.Remove("default", "000000000000000000000000"); err != nil {
t.Errorf("Error given: %s", err)
}
}