Skip to content

Commit

Permalink
Merge pull request #567 from andygrunwald/remove-WithOptions-294
Browse files Browse the repository at this point in the history
Remove the WithOptions suffixes
  • Loading branch information
andygrunwald authored Sep 12, 2022
2 parents 1a3d349 + d2547bd commit 10c0101
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 1,048 deletions.
165 changes: 165 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,178 @@ the new call would be
client.Issue.Create(ctx, ...)
```

#### `BoardService.GetAllSprints` removed, `BoardService.GetAllSprintsWithOptions` renamed

The function `client.BoardService.GetAllSprintsWithOptions()` has been renamed to `client.BoardService.GetAllSprints()`.

##### If you used `client.BoardService.GetAllSprints()`:

Before:

```go
client.Board.GetAllSprints(context.Background(), "123")
```

After:

```go
client.Board.GetAllSprints(context.Background(), "123", nil)
```

##### If you used `client.BoardService.GetAllSprintsWithOptions()`:

Before:

```go
client.Board.GetAllSprintsWithOptions(context.Background(), 123, &GetAllSprintsOptions{State: "active,future"})
```

After:

```go
client.Board.GetAllSprints(context.Background(), 123, &GetAllSprintsOptions{State: "active,future"})
```

#### `GroupService.Get` removed, `GroupService.GetWithOptions` renamed

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})
```

#### `Issue.Update` removed, `Issue.UpdateWithOptions` renamed

The function `client.Issue.UpdateWithOptions()` has been renamed to `client.Issue.Update()`.

##### If you used `client.Issue.Update()`:

Before:

```go
client.Issue.Update(context.Background(), issue)
```

After:

```go
client.Issue.Update(context.Background(), issue, nil)
```

##### If you used `client.Issue.UpdateWithOptions()`:

Before:

```go
client.Issue.UpdateWithOptions(context.Background(), issue, nil)
```

After:

```go
client.Issue.Update(context.Background(), issue, nil)
```

#### `Issue.GetCreateMeta` removed, `Issue.GetCreateMetaWithOptions` renamed

The function `client.Issue.GetCreateMetaWithOptions()` has been renamed to `client.Issue.GetCreateMeta()`.

##### If you used `client.Issue.GetCreateMeta()`:

Before:

```go
client.Issue.GetCreateMeta(context.Background(), "SPN")
```

After:

```go
client.Issue.GetCreateMetaWithOptions(ctx, &GetQueryOptions{ProjectKeys: "SPN", Expand: "projects.issuetypes.fields"})
```

##### If you used `client.Issue.GetCreateMetaWithOptions()`:

Before:

```go
client.Issue.GetCreateMetaWithOptions(ctx, &GetQueryOptions{ProjectKeys: "SPN", Expand: "projects.issuetypes.fields"})
```

After:

```go
client.Issue.GetCreateMeta(ctx, &GetQueryOptions{ProjectKeys: "SPN", Expand: "projects.issuetypes.fields"})
```

#### `Project.GetList` removed, `Project.ListWithOptions` renamed

The function `client.Project.ListWithOptions()` has been renamed to `client.Project.GetAll()`.

##### If you used `client.Project.GetList()`:

Before:

```go
client.Project.GetList(context.Background())
```

After:

```go
client.Project.GetAll(context.Background(), nil)
```

##### If you used `client.Project.ListWithOptions()`:

Before:

```go
client.Project.ListWithOptions(ctx, &GetQueryOptions{})
```

After:

```go
client.Project.GetAll(ctx, &GetQueryOptions{})
```

### Breaking changes

* Jira On-Premise and Jira Cloud have now different clients, because the API differs
* `client.NewRawRequestWithContext()` has been removed in favor of `client.NewRawRequest()`, which requires now a context as first argument
* `client.NewRequestWithContext()` has been removed in favor of `client.NewRequest()`, which requires now a context as first argument
* `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`
* `Issue.Update` has been removed and `Issue.UpdateWithOptions` has been renamed to `Issue.Update`
* `Issue.GetCreateMeta` has been removed and `Issue.GetCreateMetaWithOptions` has been renamed to `Issue.GetCreateMeta`
* `Project.GetList` has been removed and `Project.ListWithOptions` has been renamed to `Project.GetAll`

### Features

Expand Down
25 changes: 3 additions & 22 deletions cloud/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"time"
)

Expand Down Expand Up @@ -214,29 +213,11 @@ func (s *BoardService) DeleteBoard(ctx context.Context, boardID int) (*Board, *R
return nil, resp, err
}

// GetAllSprints will return all sprints from a board, for a given board Id.
// GetAllSprints returns all sprints from a board, for a given board ID.
// This only includes sprints that the user has permission to view.
//
// Jira API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
func (s *BoardService) GetAllSprints(ctx context.Context, boardID string) ([]Sprint, *Response, error) {
id, err := strconv.Atoi(boardID)
if err != nil {
return nil, nil, err
}

result, response, err := s.GetAllSprintsWithOptions(ctx, id, &GetAllSprintsOptions{})
if err != nil {
return nil, nil, err
}

return result.Values, response, nil
}

// GetAllSprintsWithOptions will return sprints from a board, for a given board Id and filtering options
// This only includes sprints that the user has permission to view.
//
// Jira API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
func (s *BoardService) GetAllSprintsWithOptions(ctx context.Context, boardID int, options *GetAllSprintsOptions) (*SprintsList, *Response, error) {
// Jira API docs: https://developer.atlassian.com/cloud/jira/software/rest/api-group-board/#api-rest-agile-1-0-board-boardid-sprint-get
func (s *BoardService) GetAllSprints(ctx context.Context, boardID int, options *GetAllSprintsOptions) (*SprintsList, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%d/sprint", boardID)
url, err := addOptions(apiEndpoint, options)
if err != nil {
Expand Down
34 changes: 1 addition & 33 deletions cloud/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,38 +161,6 @@ func TestBoardService_GetAllSprints(t *testing.T) {

testAPIEndpoint := "/rest/agile/1.0/board/123/sprint"

raw, err := os.ReadFile("../testing/mock-data/sprints.json")
if err != nil {
t.Error(err.Error())
}

testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})

sprints, _, err := testClient.Board.GetAllSprints(context.Background(), "123")

if err != nil {
t.Errorf("Got error: %v", err)
}

if sprints == nil {
t.Error("Expected sprint list. Got nil.")
}

if len(sprints) != 4 {
t.Errorf("Expected 4 transitions. Got %d", len(sprints))
}
}

func TestBoardService_GetAllSprintsWithOptions(t *testing.T) {
setup()
defer teardown()

testAPIEndpoint := "/rest/agile/1.0/board/123/sprint"

raw, err := os.ReadFile("../testing/mock-data/sprints_filtered.json")
if err != nil {
t.Error(err.Error())
Expand All @@ -204,7 +172,7 @@ func TestBoardService_GetAllSprintsWithOptions(t *testing.T) {
fmt.Fprint(w, string(raw))
})

sprints, _, err := testClient.Board.GetAllSprintsWithOptions(context.Background(), 123, &GetAllSprintsOptions{State: "active,future"})
sprints, _, err := testClient.Board.GetAllSprints(context.Background(), 123, &GetAllSprintsOptions{State: "active,future"})
if err != nil {
t.Errorf("Got error: %v", err)
}
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
13 changes: 3 additions & 10 deletions cloud/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,12 @@ func (s *IssueService) Create(ctx context.Context, issue *Issue) (*Issue, *Respo
return responseIssue, resp, nil
}

// UpdateWithOptions updates an issue from a JSON representation,
// Update updates an issue from a JSON representation,
// while also specifying query params. The issue is found by key.
//
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-editIssue
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put
// Caller must close resp.Body
func (s *IssueService) UpdateWithOptions(ctx context.Context, issue *Issue, opts *UpdateQueryOptions) (*Issue, *Response, error) {
func (s *IssueService) Update(ctx context.Context, issue *Issue, opts *UpdateQueryOptions) (*Issue, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%v", issue.Key)
url, err := addOptions(apiEndpoint, opts)
if err != nil {
Expand All @@ -831,13 +831,6 @@ func (s *IssueService) UpdateWithOptions(ctx context.Context, issue *Issue, opts
return &ret, resp, nil
}

// Update updates an issue from a JSON representation. The issue is found by key.
//
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-editIssue
func (s *IssueService) Update(ctx context.Context, issue *Issue) (*Issue, *Response, error) {
return s.UpdateWithOptions(ctx, issue, nil)
}

// UpdateIssue updates an issue from a JSON representation. The issue is found by key.
//
// https://docs.atlassian.com/jira/REST/7.4.0/#api/2/issue-editIssue
Expand Down
2 changes: 1 addition & 1 deletion cloud/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestIssueService_Update(t *testing.T) {
Description: "example bug report",
},
}
issue, _, err := testClient.Issue.Update(context.Background(), i)
issue, _, err := testClient.Issue.Update(context.Background(), i, nil)
if issue == nil {
t.Error("Expected issue. Issue is nil")
}
Expand Down
Loading

0 comments on commit 10c0101

Please sign in to comment.