mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-02-13 13:48:28 +02:00
Support state filter for GetAllSprints call
* creates a GetAllSprintsOptions structure * adds a new GetAllSprintsWithOptions method to accept an int boardID and new options structure * adds filtering functionality to GetAllSprintsWithOptions method * adds SprintsList type for handling pagination results data from GetAllSprints request * updates tests
This commit is contained in:
parent
98ede9f81c
commit
231bc31ebd
54
board.go
54
board.go
@ -2,6 +2,7 @@ package jira
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,9 +45,21 @@ type BoardListOptions struct {
|
|||||||
SearchOptions
|
SearchOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper struct for search result
|
// GetAllSprintsOptions specifies the optional parameters to the BoardService.GetList
|
||||||
type sprintsResult struct {
|
type GetAllSprintsOptions struct {
|
||||||
Sprints []Sprint `json:"values" structs:"values"`
|
// State filters results to sprints in the specified states, comma-separate list
|
||||||
|
State string `url:"state,omitempty"`
|
||||||
|
|
||||||
|
SearchOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// SprintsList reflects a list of agile sprints
|
||||||
|
type SprintsList struct {
|
||||||
|
MaxResults int `json:"maxResults" structs:"maxResults"`
|
||||||
|
StartAt int `json:"startAt" structs:"startAt"`
|
||||||
|
Total int `json:"total" structs:"total"`
|
||||||
|
IsLast bool `json:"isLast" structs:"isLast"`
|
||||||
|
Values []Sprint `json:"values" structs:"values"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprint represents a sprint on JIRA agile board
|
// Sprint represents a sprint on JIRA agile board
|
||||||
@ -67,6 +80,9 @@ type Sprint struct {
|
|||||||
func (s *BoardService) GetAllBoards(opt *BoardListOptions) (*BoardsList, *Response, error) {
|
func (s *BoardService) GetAllBoards(opt *BoardListOptions) (*BoardsList, *Response, error) {
|
||||||
apiEndpoint := "rest/agile/1.0/board"
|
apiEndpoint := "rest/agile/1.0/board"
|
||||||
url, err := addOptions(apiEndpoint, opt)
|
url, err := addOptions(apiEndpoint, opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
req, err := s.client.NewRequest("GET", url, nil)
|
req, err := s.client.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -145,22 +161,44 @@ func (s *BoardService) DeleteBoard(boardID int) (*Board, *Response, error) {
|
|||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllSprints will returns all sprints from a board, for a given board Id.
|
// GetAllSprints will return all sprints from a board, for a given board Id.
|
||||||
// This only includes sprints that the user has permission to view.
|
// 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
|
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
|
||||||
func (s *BoardService) GetAllSprints(boardID string) ([]Sprint, *Response, error) {
|
func (s *BoardService) GetAllSprints(boardID string) ([]Sprint, *Response, error) {
|
||||||
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%s/sprint", boardID)
|
id, err := strconv.Atoi(boardID)
|
||||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := new(sprintsResult)
|
result, response, err := s.GetAllSprintsWithOptions(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(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 {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
req, err := s.client.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := new(SprintsList)
|
||||||
resp, err := s.client.Do(req, result)
|
resp, err := s.client.Do(req, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = NewJiraError(resp, err)
|
err = NewJiraError(resp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Sprints, resp, err
|
return result, resp, err
|
||||||
}
|
}
|
||||||
|
@ -184,3 +184,35 @@ func TestBoardService_GetAllSprints(t *testing.T) {
|
|||||||
t.Errorf("Expected 4 transitions. Got %d", len(sprints))
|
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 := ioutil.ReadFile("./mocks/sprints_filtered.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, "GET")
|
||||||
|
testRequestURL(t, r, testAPIEndpoint)
|
||||||
|
fmt.Fprint(w, string(raw))
|
||||||
|
})
|
||||||
|
|
||||||
|
sprints, _, err := testClient.Board.GetAllSprintsWithOptions(123, &GetAllSprintsOptions{State: "active,future"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Got error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if sprints == nil {
|
||||||
|
t.Error("Expected sprint list. Got nil.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(sprints.Values) != 1 {
|
||||||
|
t.Errorf("Expected 1 transition. Got %d", len(sprints.Values))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
16
mocks/sprints_filtered.json
Normal file
16
mocks/sprints_filtered.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"isLast": true,
|
||||||
|
"maxResults": 50,
|
||||||
|
"startAt": 0,
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"endDate": "2016-06-28T14:24:00.000-07:00",
|
||||||
|
"id": 832,
|
||||||
|
"name": "Iteration-13-2",
|
||||||
|
"originBoardId": 734,
|
||||||
|
"self": "https://jira.com/rest/agile/1.0/sprint/832",
|
||||||
|
"startDate": "2016-06-20T13:24:39.161-07:00",
|
||||||
|
"state": "active"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user