Skip to content

Commit d5d3f69

Browse files
raylumk-5
authored andcommitted
fix: paginate boards
1 parent 776349a commit d5d3f69

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

internal/jira/jira_boards.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,33 @@ const (
6161

6262
type findBoardsQueryParams struct {
6363
ProjectKeyOrId string `url:"projectKeyOrId"`
64+
StartAt int `url:"startAt"`
6465
}
6566

6667
func (api *httpApi) FindBoards(projectKeyOrId string) ([]BoardItem, error) {
67-
resultBytes, err := api.jiraRequest("GET", FindAllBoardsUrl, &findBoardsQueryParams{ProjectKeyOrId: projectKeyOrId}, nil)
68-
if err != nil {
69-
return nil, err
70-
}
71-
var result BoardsResponse
72-
err = json.Unmarshal(resultBytes, &result)
73-
if err != nil {
74-
return nil, err
68+
params := &findBoardsQueryParams{ProjectKeyOrId: projectKeyOrId, StartAt: 0}
69+
var boards []BoardItem
70+
for {
71+
resultBytes, err := api.jiraRequest("GET", FindAllBoardsUrl, params, nil)
72+
if err != nil {
73+
return nil, err
74+
}
75+
var result BoardsResponse
76+
err = json.Unmarshal(resultBytes, &result)
77+
if err != nil {
78+
return nil, err
79+
}
80+
if cap(boards) == 0 {
81+
boards = make([]BoardItem, 0, result.Total)
82+
}
83+
boards = append(boards, result.Values...)
84+
85+
if result.IsLast {
86+
break
87+
}
88+
params.StartAt += result.MaxResults
7589
}
76-
return result.Values, nil
90+
return boards, nil
7791
}
7892

7993
func (api *httpApi) GetBoardConfiguration(boardId int) (*BoardConfiguration, error) {

0 commit comments

Comments
 (0)