Skip to content

fix(backend): stop Gitea/Forgejo pagination on empty page response#1130

Merged
brendan-kellam merged 2 commits intomainfrom
claude/issue-1108-20260417-2355
Apr 18, 2026
Merged

fix(backend): stop Gitea/Forgejo pagination on empty page response#1130
brendan-kellam merged 2 commits intomainfrom
claude/issue-1108-20260417-2355

Conversation

@brendan-kellam
Copy link
Copy Markdown
Contributor

@brendan-kellam brendan-kellam commented Apr 17, 2026

When an API token can only see a subset of org repos, the x-total-count header reports the org total while the token returns fewer items. The previous loop condition (output.length < totalCount) would never be satisfied for the visible subset, causing infinite pagination and effectively DoS-ing the Gitea/Forgejo instance.

The fix breaks out of the loop when the API returns an empty page, matching the Gitea API pagination docs recommendation.

Fixes #1108

Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed infinite pagination loops in Gitea/Forgejo integrations that occurred when API tokens had restricted access to certain repositories. The pagination system now correctly detects when all available results have been retrieved and terminates appropriately, preventing endless looping and excessive API requests while significantly improving overall system stability, reliability, and performance.

When an API token can only see a subset of org repos, the x-total-count
header reports the org total while the token returns fewer items. The
previous loop condition (output.length < totalCount) would never be
satisfied for the visible subset, causing infinite pagination.

Now we break out of the loop when the API returns an empty page,
matching the Gitea API pagination docs recommendation.

Fixes #1108

Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com>
@github-actions

This comment has been minimized.

@brendan-kellam
Copy link
Copy Markdown
Contributor Author

@claude add a changelog entry

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b019718c-38e8-4765-b537-caeb59fe9032

📥 Commits

Reviewing files that changed from the base of the PR and between 06c379a and bdfcd1c.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • packages/backend/src/gitea.ts

Walkthrough

This fix addresses an infinite pagination loop in Gitea/Forgejo API calls when an API token lacks visibility to all organization repositories. The pagination now breaks early when an empty page is received, preventing unlimited requests regardless of the reported total count.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added entry documenting the fix for infinite pagination loops in Gitea/Forgejo scenarios where token access is restricted to a subset of org repositories.
Pagination Logic
packages/backend/src/gitea.ts
Added early exit condition in paginate() function to break the loop when result.data.length === 0, preventing infinite requests when API returns empty pages while reported total count remains higher.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary fix: stopping pagination on empty page responses in Gitea/Forgejo pagination logic.
Linked Issues check ✅ Passed The PR directly addresses issue #1108 by implementing the expected behavior: breaking pagination when API returns empty page, preventing infinite loops.
Out of Scope Changes check ✅ Passed All changes (paginate function guard + CHANGELOG entry) are directly related to fixing the infinite pagination issue described in #1108.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-1108-20260417-2355

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link
Copy Markdown

claude bot commented Apr 18, 2026

Claude finished @brendan-kellam's task in 39s —— View job


Changelog Entry Added

  • Gather context
  • Read CHANGELOG.md
  • Add changelog entry under [Unreleased]
  • Commit and push

Added the following entry to CHANGELOG.md under [Unreleased] > Fixed:

Fixed infinite pagination loop in Gitea/Forgejo when an API token can only see a subset of org repos (the x-total-count header reports org total while token returns fewer items). #1130

Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com>
@brendan-kellam brendan-kellam merged commit 2952daa into main Apr 18, 2026
8 checks passed
@brendan-kellam brendan-kellam deleted the claude/issue-1108-20260417-2355 branch April 18, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Infinite API pagination loop when Gitea/Forgejo token cannot see all org repos

1 participant