@@ -2,6 +2,7 @@ package jira
22
33import (
44 "fmt"
5+ "strconv"
56 "time"
67)
78
@@ -44,9 +45,21 @@ type BoardListOptions struct {
4445 SearchOptions
4546}
4647
47- // Wrapper struct for search result
48- type sprintsResult struct {
49- Sprints []Sprint `json:"values" structs:"values"`
48+ // GetAllSprintsOptions specifies the optional parameters to the BoardService.GetList
49+ type GetAllSprintsOptions struct {
50+ // State filters results to sprints in the specified states, comma-separate list
51+ State string `url:"state,omitempty"`
52+
53+ SearchOptions
54+ }
55+
56+ // SprintsList reflects a list of agile sprints
57+ type SprintsList struct {
58+ MaxResults int `json:"maxResults" structs:"maxResults"`
59+ StartAt int `json:"startAt" structs:"startAt"`
60+ Total int `json:"total" structs:"total"`
61+ IsLast bool `json:"isLast" structs:"isLast"`
62+ Values []Sprint `json:"values" structs:"values"`
5063}
5164
5265// Sprint represents a sprint on JIRA agile board
@@ -67,6 +80,9 @@ type Sprint struct {
6780func (s * BoardService ) GetAllBoards (opt * BoardListOptions ) (* BoardsList , * Response , error ) {
6881 apiEndpoint := "rest/agile/1.0/board"
6982 url , err := addOptions (apiEndpoint , opt )
83+ if err != nil {
84+ return nil , nil , err
85+ }
7086 req , err := s .client .NewRequest ("GET" , url , nil )
7187 if err != nil {
7288 return nil , nil , err
@@ -145,22 +161,44 @@ func (s *BoardService) DeleteBoard(boardID int) (*Board, *Response, error) {
145161 return nil , resp , err
146162}
147163
148- // GetAllSprints will returns all sprints from a board, for a given board Id.
164+ // GetAllSprints will return all sprints from a board, for a given board Id.
149165// This only includes sprints that the user has permission to view.
150166//
151167// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
152168func (s * BoardService ) GetAllSprints (boardID string ) ([]Sprint , * Response , error ) {
153- apiEndpoint := fmt .Sprintf ("rest/agile/1.0/board/%s/sprint" , boardID )
154- req , err := s .client .NewRequest ("GET" , apiEndpoint , nil )
169+ id , err := strconv .Atoi (boardID )
170+ if err != nil {
171+ return nil , nil , err
172+ }
173+
174+ result , response , err := s .GetAllSprintsWithOptions (id , & GetAllSprintsOptions {})
175+ if err != nil {
176+ return nil , nil , err
177+ }
178+
179+ return result .Values , response , nil
180+ }
181+
182+ // GetAllSprintsWithOptions will return sprints from a board, for a given board Id and filtering options
183+ // This only includes sprints that the user has permission to view.
184+ //
185+ // JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint
186+ func (s * BoardService ) GetAllSprintsWithOptions (boardID int , options * GetAllSprintsOptions ) (* SprintsList , * Response , error ) {
187+ apiEndpoint := fmt .Sprintf ("rest/agile/1.0/board/%d/sprint" , boardID )
188+ url , err := addOptions (apiEndpoint , options )
189+ if err != nil {
190+ return nil , nil , err
191+ }
192+ req , err := s .client .NewRequest ("GET" , url , nil )
155193 if err != nil {
156194 return nil , nil , err
157195 }
158196
159- result := new (sprintsResult )
197+ result := new (SprintsList )
160198 resp , err := s .client .Do (req , result )
161199 if err != nil {
162200 err = NewJiraError (resp , err )
163201 }
164202
165- return result . Sprints , resp , err
203+ return result , resp , err
166204}
0 commit comments