1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-08-06 22:13:02 +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:
Shawn Catanzarite
2018-06-07 16:08:02 -07:00
parent 98ede9f81c
commit 231bc31ebd
3 changed files with 94 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package jira
import (
"fmt"
"strconv"
"time"
)
@ -44,9 +45,21 @@ type BoardListOptions struct {
SearchOptions
}
// Wrapper struct for search result
type sprintsResult struct {
Sprints []Sprint `json:"values" structs:"values"`
// GetAllSprintsOptions specifies the optional parameters to the BoardService.GetList
type GetAllSprintsOptions struct {
// 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
@ -67,6 +80,9 @@ type Sprint struct {
func (s *BoardService) GetAllBoards(opt *BoardListOptions) (*BoardsList, *Response, error) {
apiEndpoint := "rest/agile/1.0/board"
url, err := addOptions(apiEndpoint, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
@ -145,22 +161,44 @@ func (s *BoardService) DeleteBoard(boardID int) (*Board, *Response, error) {
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.
//
// 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) {
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%s/sprint", boardID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
id, err := strconv.Atoi(boardID)
if err != nil {
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)
if err != nil {
err = NewJiraError(resp, err)
}
return result.Sprints, resp, err
return result, resp, err
}