Skip to content

Fix next page calculation bug in GitEa provider pagination #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 3, 2025

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:

if i >= currentPage {  // BUG: This logic is backwards
    return false, i
}

Where:

  • i represents the total number of pages from the x-pagecount header
  • currentPage is the current page being processed

This 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:

  • Page 1 of 5: 5 >= 1 is true → returns false (should be true)
  • Page 2 of 5: 5 >= 2 is true → returns false (should be true)
  • Page 5 of 5: 5 >= 5 is true → returns false (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:

if currentPage >= i {  // FIXED: Correct logic
    return false, i
}

Now the logic correctly identifies when we've reached the last page:

  • Page 1 of 5: 1 >= 5 is false → returns true (correct)
  • Page 2 of 5: 2 >= 5 is false → returns true (correct)
  • Page 5 of 5: 5 >= 5 is true → returns false (correct)

Changes Made

  1. Fixed the pagination logic in ShouldGetNextPage function
  2. Added comprehensive test coverage with 6 test cases covering:
    • First page, middle pages, and last page scenarios
    • Single page scenario
    • Edge cases (missing header, invalid header values)

Testing

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
    • Triggering command: /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
    • Triggering command: /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
    • Triggering command: /tmp/go-build378190642/b1491/github.test -test.testlogfile=/tmp/go-build378190642/b1491/testlog.txt -test.paniconexit0 -test.failfast=true -test.timeout=20m0s (http block)
    • Triggering command: /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
    • Triggering command: /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.

Copy link

Deploying pipelines-as-code with  Cloudflare Pages  Cloudflare Pages

Latest commit: bc4c183
Status: ✅  Deploy successful!
Preview URL: https://0927293b.pipelines-as-code.pages.dev
Branch Preview URL: https://copilot-fix-776c106f-100f-40.pipelines-as-code.pages.dev

View logs

@chmouel chmouel deleted the copilot/fix-776c106f-100f-406b-a185-382e734bad4f branch July 3, 2025 15:58
@Copilot Copilot AI restored the copilot/fix-776c106f-100f-406b-a185-382e734bad4f branch July 3, 2025 16:06
@Copilot Copilot AI changed the title [WIP] there is a bug in calculation for next meeting Fix next page calculation bug in GitEa provider pagination Jul 3, 2025
@Copilot Copilot AI requested a review from chmouel July 3, 2025 16:11
Copilot finished work on behalf of chmouel July 3, 2025 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants