Fix next page calculation bug in GitEa provider pagination #2161
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.
Problem
The
ShouldGetNextPage
function in the GitEa provider had incorrect logic for determining when to fetch the next page in pagination. This caused the provider to stop pagination prematurely after the first page when fetching pull request files or other paginated resources.Root Cause
The bug was in line 392 of
pkg/provider/gitea/gitea.go
:Where:
i
represents the total number of pages from thex-pagecount
headercurrentPage
is the current page being processedThis condition was backwards - it would return
false
(don't fetch next page) when the total pages was greater than or equal to the current page, which is exactly when we should continue pagination.Example of the Bug
For a 5-page result set:
5 >= 1
is true → returnsfalse
(should betrue
)5 >= 2
is true → returnsfalse
(should betrue
)5 >= 5
is true → returnsfalse
(correct)This meant only the first page of results would ever be retrieved.
Solution
Fixed the condition to correctly compare current page against total pages:
Now the logic correctly identifies when we've reached the last page:
1 >= 5
is false → returnstrue
(correct)2 >= 5
is false → returnstrue
(correct)5 >= 5
is true → returnsfalse
(correct)Changes Made
ShouldGetNextPage
functionTesting
All tests pass, including the new comprehensive test suite for
ShouldGetNextPage
that validates the fix across multiple scenarios. The fix ensures that GitEa provider will now correctly retrieve all pages of paginated results instead of stopping after the first page.Impact
This bug was preventing complete file change information from being retrieved in GitEa pull requests when the changes spanned multiple pages. The fix ensures all changed files are properly discovered and processed.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
api.bitbucket.org
/tmp/go-build378190642/b1330/webhook.test -test.testlogfile=/tmp/go-build378190642/b1330/testlog.txt -test.paniconexit0 -test.failfast=true -test.timeout=20m0s
(dns block)https://api.github.com/app/installations
/tmp/go-build378190642/b1074/adapter.test -test.testlogfile=/tmp/go-build378190642/b1074/testlog.txt -test.paniconexit0 -test.failfast=true -test.timeout=20m0s
(http block)https://api.github.com/app/installations/1234567/access_tokens
/tmp/go-build378190642/b1491/github.test -test.testlogfile=/tmp/go-build378190642/b1491/testlog.txt -test.paniconexit0 -test.failfast=true -test.timeout=20m0s
(http block)/tmp/go-build2210641935/b1169/github.test -test.testlogfile=/tmp/go-build2210641935/b1169/testlog.txt -test.paniconexit0 -test.timeout=10m0s
(http block)https://api.github.com/repos/owner/repo/hooks
/tmp/go-build378190642/b1383/webhook.test -test.testlogfile=/tmp/go-build378190642/b1383/testlog.txt -test.paniconexit0 -test.failfast=true -test.timeout=20m0s
(http block)mybelovedhub
If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.