From 33e2fcb3627710e85fb008dc6ef5023f0d8fac30 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Mon, 12 Sep 2022 20:01:28 +0200 Subject: [PATCH] BoardService: `BoardService.GetAllSprints` removed, `BoardService.GetAllSprintsWithOptions` renamed Related #294 --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++++ cloud/board.go | 25 +++---------------------- cloud/board_test.go | 34 +--------------------------------- onpremise/board.go | 25 +++---------------------- onpremise/board_test.go | 34 +--------------------------------- 5 files changed, 43 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba003dee..a8f5c9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -166,6 +166,40 @@ 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 @@ -173,6 +207,7 @@ client.Issue.Create(ctx, ...) * `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 diff --git a/cloud/board.go b/cloud/board.go index 37b5167a..992a378d 100644 --- a/cloud/board.go +++ b/cloud/board.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strconv" "time" ) @@ -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 { diff --git a/cloud/board_test.go b/cloud/board_test.go index 2495dcef..099c424a 100644 --- a/cloud/board_test.go +++ b/cloud/board_test.go @@ -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()) @@ -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) } diff --git a/onpremise/board.go b/onpremise/board.go index 14045201..8b92be72 100644 --- a/onpremise/board.go +++ b/onpremise/board.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strconv" "time" ) @@ -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 { diff --git a/onpremise/board_test.go b/onpremise/board_test.go index 3ec06aaf..894876b5 100644 --- a/onpremise/board_test.go +++ b/onpremise/board_test.go @@ -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()) @@ -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) }