Skip to content

Commit f4ee809

Browse files
committed
1 parent 5157b9d commit f4ee809

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ module irontec.com/jrquery
33
go 1.22.5
44

55
require (
6-
github.com/andygrunwald/go-jira/v2 v2.0.0-20241105083653-2bb8c510ed50
6+
github.com/andygrunwald/go-jira/v2 v2.0.0-20250914065312-05fb5bc92aec
77
github.com/jessevdk/go-flags v1.6.1
88
github.com/spf13/viper v1.19.0
99
)
1010

11+
//replace github.com/andygrunwald/go-jira/v2 => github.com/space307/go-jira/v2 v2.0.0-20250903122123-5a66328fccfb
12+
1113
require (
1214
github.com/fatih/structs v1.1.0 // indirect
1315
github.com/fsnotify/fsnotify v1.7.0 // indirect
14-
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
16+
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
1517
github.com/google/go-querystring v1.1.0 // indirect
1618
github.com/hashicorp/hcl v1.0.0 // indirect
1719
github.com/magiconair/properties v1.8.7 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/andygrunwald/go-jira/v2 v2.0.0-20241105083653-2bb8c510ed50 h1:VDDR6L0h8ocCoW0Bqqc4vB0tbGjFUrajSmkmgQKKMFc=
2-
github.com/andygrunwald/go-jira/v2 v2.0.0-20241105083653-2bb8c510ed50/go.mod h1:7OuxlDEDC9Q9Lp3nw0f5F+UiLsx/b8YMp8OkKbp0uX0=
1+
github.com/andygrunwald/go-jira/v2 v2.0.0-20250914065312-05fb5bc92aec h1:hYTOh5SnGhTyya5hgDHJ6xDfmbPXAbWmTxwRc/OppT8=
2+
github.com/andygrunwald/go-jira/v2 v2.0.0-20250914065312-05fb5bc92aec/go.mod h1:PmolOmLs9fDr4F240qyXuTuurFxblZiQKTztY+xAmKw=
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -10,11 +10,11 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
1010
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1111
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1212
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
13-
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
14-
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
13+
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
14+
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
1515
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
16-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
17-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
16+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
17+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1818
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
1919
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
2020
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=

internal/jira/client.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ func (c *Client) GetIssue(ctx context.Context, issueKey string) (*cloud.Issue, e
4646
// SearchIssuesWithPagination fetches issues based on a JQL query with pagination and applies a result limit.
4747
func (c *Client) SearchIssuesWithPagination(jql string, maxResults int) (*IssueList, error) {
4848
var allIssues []cloud.Issue
49-
startAt := 0
5049
totalFetched := 0
5150
pageSize := 50
5251
total := 0
52+
nextPageToken := ""
5353

5454
for {
5555
// Fetch issues in pages of size pageSize
56-
issueList, err := c.SearchIssues(jql, startAt, pageSize)
56+
issueList, response, err := c.SearchIssues(jql, nextPageToken, pageSize)
5757
if err != nil {
5858
return nil, fmt.Errorf("error fetching issues with pagination: %w", err)
5959
}
@@ -82,27 +82,28 @@ func (c *Client) SearchIssuesWithPagination(jql string, maxResults int) (*IssueL
8282
}
8383

8484
// Move to the next page
85-
startAt += pageSize
85+
nextPageToken = response.NextPageToken
8686
}
8787

8888
// Return the combined issue list with the total count and max results
8989
return NewIssueList(allIssues, len(allIssues), total), nil
9090
}
9191

9292
// SearchIssues executes a JQL query to find issues in Jira.
93-
func (c *Client) SearchIssues(jql string, start, limit int) (*IssueList, error) {
94-
searchOptions := &cloud.SearchOptions{
95-
StartAt: start,
96-
MaxResults: limit,
93+
func (c *Client) SearchIssues(jql string, nextPageToken string, limit int) (*IssueList, *cloud.Response, error) {
94+
searchOptions := &cloud.SearchOptionsV2{
95+
NextPageToken: nextPageToken,
96+
MaxResults: limit,
97+
Fields: []string{"*all"},
9798
}
9899

99-
issues, response, err := c.apiClient.Issue.Search(context.Background(), jql, searchOptions)
100+
issues, response, err := c.apiClient.Issue.SearchV2JQL(context.Background(), jql, searchOptions)
100101
if err != nil {
101-
return nil, fmt.Errorf("error executing JQL query: %w", err)
102+
return nil, nil, fmt.Errorf("error executing JQL query: %w", err)
102103
}
103104

104105
// Create an IssueList
105-
return NewIssueList(issues, response.MaxResults, response.Total), nil
106+
return NewIssueList(issues, response.MaxResults, response.Total), response, nil
106107
}
107108

108109
// SearchIssuesByFilter retrieves issues using a pre-existing saved filter by its ID and returns an IssueList with pagination.
@@ -112,19 +113,20 @@ func (c *Client) SearchIssuesByFilter(filterID string, limit int) (*IssueList, e
112113

113114
// Initialize pagination variables
114115
var allIssues []cloud.Issue
115-
startAt := 0
116116
fetchLimit := 100 // Set a limit for each page of results (maximum Jira allows is 1000)
117117

118118
// Iterate over pages of issues
119+
nextPageToken := ""
119120
for {
120121
// Create the search options with pagination
121-
searchOptions := &cloud.SearchOptions{
122-
StartAt: startAt,
123-
MaxResults: fetchLimit,
122+
searchOptions := &cloud.SearchOptionsV2{
123+
NextPageToken: nextPageToken,
124+
MaxResults: fetchLimit,
125+
Fields: []string{"*all"},
124126
}
125127

126128
// Execute the search with the saved filter
127-
issues, response, err := c.apiClient.Issue.Search(context.Background(), jql, searchOptions)
129+
issues, response, err := c.apiClient.Issue.SearchV2JQL(context.Background(), jql, searchOptions)
128130
if err != nil {
129131
return nil, fmt.Errorf("error executing JQL query with filter %s: %w", filterID, err)
130132
}
@@ -133,12 +135,11 @@ func (c *Client) SearchIssuesByFilter(filterID string, limit int) (*IssueList, e
133135
allIssues = append(allIssues, issues...)
134136

135137
// Check if there are more pages to fetch
136-
if len(allIssues) >= limit || len(allIssues) >= response.Total {
138+
if len(allIssues) >= limit || response.IsLast {
137139
break
138140
}
139141

140-
// Update the starting point for the next page
141-
startAt += fetchLimit
142+
nextPageToken = response.NextPageToken
142143
}
143144

144145
// Return the IssueList with the fetched issues and pagination details

0 commit comments

Comments
 (0)