Skip to content

Commit

Permalink
GroupService: GroupService.Get removed, `GroupService.GetWithOption…
Browse files Browse the repository at this point in the history
…s` renamed

Related #294
  • Loading branch information
andygrunwald committed Sep 12, 2022
1 parent 33e2fcb commit 295e4c7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 80 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
26 changes: 3 additions & 23 deletions cloud/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 2 additions & 17 deletions cloud/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":"[email protected]","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"[email protected]","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()
Expand All @@ -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,
Expand All @@ -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,
Expand Down
26 changes: 3 additions & 23 deletions onpremise/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 2 additions & 17 deletions onpremise/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":"[email protected]","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"[email protected]","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()
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 295e4c7

Please sign in to comment.