fix: Restore pagination support for v3 JQL search API #926
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #898
Problem
After the migration to the new Jira v3 JQL search endpoint in PR #892, pagination using the
--paginateflag is broken for Cloud installations. Thefrom(offset) parameter in--paginate <from>:<limit>is silently ignored, causing all pagination queries to return the same results regardless of the specified offset.For example, these commands all return identical results:
This happens because the new
/rest/api/3/search/jqlendpoint does not support thestartAtparameter that the v2 API used. Instead, it uses cursor-based pagination vianextPageTokenandisLastfields.Solution
Implemented cursor-based pagination in the
Search()function to support thefromoffset parameter:Search()to accept afromparameternextPageTokento iterate through result pagesThis maintains backward compatibility with the existing
--paginate from:limitinterface while working with the new Jira v3 API.Changes
pkg/jira/search.go- RewroteSearch()to implement cursor-based pagination with offset supportmaxSearchPageSizeconstant (100) for clarityIsLastfield based on whether all results were fetchedpkg/jira/search_test.go- Added comprehensive pagination test coverage (11 tests)api/client.go- UpdatedProxySearch()to passfromparameter toSearch()internal/cmd/epic/list/list.go- Updated twoSearch()call sites to includefromparameterTesting
Unit Tests
Added 11 unit tests in
pkg/jira/search_test.gocovering:nextPageTokennextPageTokenis correctly passed in subsequent requestsIsLastis true when all pages exhaustedIsLastis false when limit reached before endRun with:
go test ./pkg/jira/... -run TestSearchPagination -vManual Testing
test-pagination.sh
Notes
startAtand are unaffected by this changeBreaking Changes
The
Search()function signature inpkg/jirachanged from:to:
This is necessary to support pagination offsets. External code importing
pkg/jiradirectly (uncommon) would need to add thefromparameter. The CLI interface (--paginate) is unchanged.