Skip to content

Commit 2952daa

Browse files
fix(backend): stop Gitea/Forgejo pagination on empty page response (#1130)
* fix(backend): stop Gitea/Forgejo pagination on empty page response 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> * chore: add changelog entry for Gitea/Forgejo pagination fix Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com>
1 parent 219fac6 commit 2952daa

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- Fixed revision selection so the 64-revision cap prefers the newest matching branches and tags instead of pruning by ref-name order. [#1122](https://github.com/sourcebot-dev/sourcebot/pull/1122)
12+
- 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](https://github.com/sourcebot-dev/sourcebot/pull/1130)
1213

1314
## [4.16.11] - 2026-04-17
1415

packages/backend/src/gitea.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ const paginate = async <T>(request: (page: number) => Promise<HttpResponse<T[],
254254
while (output.length < totalCount) {
255255
page++;
256256
const result = await request(page);
257+
if (result.data.length === 0) {
258+
break;
259+
}
257260
output.push(...result.data);
258261
}
259262

0 commit comments

Comments
 (0)