From 295e4c79b1c596414ead33d8bb1de931efab11c1 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Mon, 12 Sep 2022 20:10:36 +0200 Subject: [PATCH] GroupService: `GroupService.Get` removed, `GroupService.GetWithOptions` renamed Related #294 --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++++ cloud/group.go | 26 +++----------------------- cloud/group_test.go | 19 ++----------------- onpremise/group.go | 26 +++----------------------- onpremise/group_test.go | 19 ++----------------- 5 files changed, 45 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f5c9a1..130f3844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -200,6 +200,40 @@ After: client.Board.GetAllSprints(context.Background(), 123, &GetAllSprintsOptions{State: "active,future"}) ``` +#### `GroupService.Get` removed, `GroupService.GetWithOptions` renamed + + +The function `client.GroupService.Get()` has been removed. +The function `client.GroupService.GetWithOptions()` has been renamed to `client.GroupService.Get()`. + +##### If you used `client.GroupService.Get()`: + +Before: + +```go +client.Group.Get(context.Background(), "default") +``` + +After: + +```go +client.Group.Get(context.Background(), "default", nil) +``` + +##### If you used `client.GroupService.GetWithOptions()`: + +Before: + +```go +client.Group.GetWithOptions(context.Background(), "default", &GroupSearchOptions{StartAt: 0, MaxResults: 2}) +``` + +After: + +```go +client.Group.Get(context.Background(), "default", &GroupSearchOptions{StartAt: 0, MaxResults: 2}) +``` + ### Breaking changes * Jira On-Premise and Jira Cloud have now different clients, because the API differs @@ -208,6 +242,7 @@ client.Board.GetAllSprints(context.Background(), 123, &GetAllSprintsOptions{Stat * `client.NewMultiPartRequestWithContext()` has been removed in favor of `client.NewMultiPartRequest()`, which requires now a context as first argument * `context` is now a first class citizen in all API calls. Functions that had a suffix like `...WithContext` have been removed entirely. The API methods support the context now as first argument. * `BoardService.GetAllSprints` has been removed and `BoardService.GetAllSprintsWithOptions` has been renamed to `BoardService.GetAllSprints` +* `GroupService.Get` has been removed and `GroupService.GetWithOptions` has been renamed to `GroupService.Get` ### Features diff --git a/cloud/group.go b/cloud/group.go index 5a3da1c3..6bd765f4 100644 --- a/cloud/group.go +++ b/cloud/group.go @@ -58,39 +58,19 @@ type GroupSearchOptions struct { IncludeInactiveUsers bool } -// Get returns a paginated list of users who are members of the specified group and its subgroups. +// Get returns a paginated list of members of the specified group and its subgroups. // Users in the page are ordered by user names. // User of this resource is required to have sysadmin or admin permissions. // // Jira API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup // // WARNING: This API only returns the first page of group members -func (s *GroupService) Get(ctx context.Context, name string) ([]GroupMember, *Response, error) { - apiEndpoint := fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name)) - req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) - if err != nil { - return nil, nil, err - } - - group := new(groupMembersResult) - resp, err := s.client.Do(req, group) - if err != nil { - return nil, resp, err - } - - return group.Members, resp, nil -} - -// GetWithOptions returns a paginated list of members of the specified group and its subgroups. -// Users in the page are ordered by user names. -// User of this resource is required to have sysadmin or admin permissions. -// -// Jira API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup -func (s *GroupService) GetWithOptions(ctx context.Context, name string, options *GroupSearchOptions) ([]GroupMember, *Response, error) { +func (s *GroupService) Get(ctx context.Context, name string, options *GroupSearchOptions) ([]GroupMember, *Response, error) { var apiEndpoint string if options == nil { apiEndpoint = fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name)) } else { + // TODO use addOptions apiEndpoint = fmt.Sprintf( "/rest/api/2/group/member?groupname=%s&startAt=%d&maxResults=%d&includeInactiveUsers=%t", url.QueryEscape(name), diff --git a/cloud/group_test.go b/cloud/group_test.go index 43fff232..596ac61e 100644 --- a/cloud/group_test.go +++ b/cloud/group_test.go @@ -7,21 +7,6 @@ import ( "testing" ) -func TestGroupService_Get(t *testing.T) { - setup() - defer teardown() - testMux.HandleFunc("/rest/api/2/group/member", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodGet) - testRequestURL(t, r, "/rest/api/2/group/member?groupname=default") - fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=50&groupname=default&startAt=0","maxResults":50,"startAt":0,"total":2,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`) - }) - if members, _, err := testClient.Group.Get(context.Background(), "default"); err != nil { - t.Errorf("Error given: %s", err) - } else if members == nil { - t.Error("Expected members. Group.Members is nil") - } -} - func TestGroupService_GetPage(t *testing.T) { setup() defer teardown() @@ -37,7 +22,7 @@ func TestGroupService_GetPage(t *testing.T) { t.Errorf("startAt %s", startAt) } }) - if page, resp, err := testClient.Group.GetWithOptions(context.Background(), "default", &GroupSearchOptions{ + if page, resp, err := testClient.Group.Get(context.Background(), "default", &GroupSearchOptions{ StartAt: 0, MaxResults: 2, IncludeInactiveUsers: false, @@ -55,7 +40,7 @@ func TestGroupService_GetPage(t *testing.T) { if resp.Total != 4 { t.Errorf("Expect Result Total to be 4, but is %d", resp.Total) } - if page, resp, err := testClient.Group.GetWithOptions(context.Background(), "default", &GroupSearchOptions{ + if page, resp, err := testClient.Group.Get(context.Background(), "default", &GroupSearchOptions{ StartAt: 2, MaxResults: 2, IncludeInactiveUsers: false, diff --git a/onpremise/group.go b/onpremise/group.go index 44074eec..07a36943 100644 --- a/onpremise/group.go +++ b/onpremise/group.go @@ -58,39 +58,19 @@ type GroupSearchOptions struct { IncludeInactiveUsers bool } -// Get returns a paginated list of users who are members of the specified group and its subgroups. +// Get returns a paginated list of members of the specified group and its subgroups. // Users in the page are ordered by user names. // User of this resource is required to have sysadmin or admin permissions. // // Jira API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup // // WARNING: This API only returns the first page of group members -func (s *GroupService) Get(ctx context.Context, name string) ([]GroupMember, *Response, error) { - apiEndpoint := fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name)) - req, err := s.client.NewRequest(ctx, http.MethodGet, apiEndpoint, nil) - if err != nil { - return nil, nil, err - } - - group := new(groupMembersResult) - resp, err := s.client.Do(req, group) - if err != nil { - return nil, resp, err - } - - return group.Members, resp, nil -} - -// GetWithOptions returns a paginated list of members of the specified group and its subgroups. -// Users in the page are ordered by user names. -// User of this resource is required to have sysadmin or admin permissions. -// -// Jira API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup -func (s *GroupService) GetWithOptions(ctx context.Context, name string, options *GroupSearchOptions) ([]GroupMember, *Response, error) { +func (s *GroupService) Get(ctx context.Context, name string, options *GroupSearchOptions) ([]GroupMember, *Response, error) { var apiEndpoint string if options == nil { apiEndpoint = fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name)) } else { + // TODO use addOptions apiEndpoint = fmt.Sprintf( "/rest/api/2/group/member?groupname=%s&startAt=%d&maxResults=%d&includeInactiveUsers=%t", url.QueryEscape(name), diff --git a/onpremise/group_test.go b/onpremise/group_test.go index 125db709..9ffd6bab 100644 --- a/onpremise/group_test.go +++ b/onpremise/group_test.go @@ -7,21 +7,6 @@ import ( "testing" ) -func TestGroupService_Get(t *testing.T) { - setup() - defer teardown() - testMux.HandleFunc("/rest/api/2/group/member", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodGet) - testRequestURL(t, r, "/rest/api/2/group/member?groupname=default") - fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=50&groupname=default&startAt=0","maxResults":50,"startAt":0,"total":2,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`) - }) - if members, _, err := testClient.Group.Get(context.Background(), "default"); err != nil { - t.Errorf("Error given: %s", err) - } else if members == nil { - t.Error("Expected members. Group.Members is nil") - } -} - func TestGroupService_GetPage(t *testing.T) { setup() defer teardown() @@ -37,7 +22,7 @@ func TestGroupService_GetPage(t *testing.T) { t.Errorf("startAt %s", startAt) } }) - if page, resp, err := testClient.Group.GetWithOptions(context.Background(), "default", &GroupSearchOptions{ + if page, resp, err := testClient.Group.Get(context.Background(), "default", &GroupSearchOptions{ StartAt: 0, MaxResults: 2, IncludeInactiveUsers: false, @@ -55,7 +40,7 @@ func TestGroupService_GetPage(t *testing.T) { if resp.Total != 4 { t.Errorf("Expect Result Total to be 4, but is %d", resp.Total) } - if page, resp, err := testClient.Group.GetWithOptions(context.Background(), "default", &GroupSearchOptions{ + if page, resp, err := testClient.Group.Get(context.Background(), "default", &GroupSearchOptions{ StartAt: 2, MaxResults: 2, IncludeInactiveUsers: false,