Skip to content

Commit

Permalink
BoardService: BoardService.GetAllSprints removed, `BoardService.Get…
Browse files Browse the repository at this point in the history
…AllSprintsWithOptions` renamed

Related #294
  • Loading branch information
andygrunwald committed Sep 12, 2022
1 parent 1a3d349 commit 33e2fcb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 110 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,48 @@ the new call would be
client.Issue.Create(ctx, ...)
```

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


The function `client.BoardService.GetAllSprints()` has been removed.
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"})
```

### 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`

### 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
25 changes: 3 additions & 22 deletions onpremise/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 onpremise/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

0 comments on commit 33e2fcb

Please sign in to comment.