@@ -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.
4747func (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