fix(git-providers): fall back to the page length when GitLab omits x-total - #7120
Closed
pedrofrxncx wants to merge 1 commit into
Closed
pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
…total Number(null) is 0, not NaN, so searchBranches read a missing x-total header as a real total of 0 instead of falling back to the returned page's length — exactly backwards from what the function's own comment says GitLab's omission means (a very large project GitLab stopped counting on). A branch search on such a project reported 0 total matches while still returning branches, which a branch picker would render as an empty/broken result. Extracted the header parsing into totalCountFromHeader and unit-tested it directly, matching this file's existing pattern for testable pure helpers.
Collaborator
Author
|
Closing as stale: this PR sat past the bot's 48h merge window, main has moved on, and its CI results no longer reflect the current base. This is a housekeeping close, not a rejection of the change — if the underlying problem still exists, the bot will find it again and open a fresh, rebased PR. [studio-bot:stale-close] |
pedrofrxncx
deleted the
fix/gitlab-branch-total-count-missing-header-w1
branch
September 14, 2026 14:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug found while hardening
apps/api/src/git-providers/gitlab/*(GitLab provider client area).Payoff:
GitlabContentClient.searchBranchespowers the branch picker (apps/web/src/components/thread/github/use-branches.ts) viatotalCount. On a self-hosted or very large GitLab project, GitLab omits thex-totalheader (documented in this function's own comment as a known case), and the returned page's length is meant to be the fallback. ButNumber(res.headers.get("x-total"))on a missing header isNumber(null)=0, notNaN— soNumber.isFinite(total)wastrueand the function reported a real total of0while still returning actual branches, exactly backwards from the documented intent.Failure scenario: searching branches on a project large enough that GitLab stops counting matches renders as "0 results" in the branch picker even though branches were returned.
Fix: extracted the header parsing into a small pure
totalCountFromHeader(headerValue, fallback)helper that distinguishes an absent header from a present-and-zero one, and unit-tested it directly (matching this file's existing pattern of testable pure helpers likemapCompareDiff/parseChangesCount).Verify:
bun test apps/api/src/git-providers/gitlab/content.test.tsChecks run locally:
bun run fmt,cd apps/api && bunx tsc --noEmit(clean), the targeted test file above (51 pass),bunx oxlinton both touched files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Fixes the GitLab branch picker showing 0 results on large projects by correctly falling back to the page length when GitLab omits the
x-totalheader. Previously a missing header was read as 0 (viaNumber(null)), sosearchBranchesreported a total of 0 while still returning branches; now an absent or unparseable header uses the returned branches' length.totalCountFromHeaderhelper and adds unit tests for it.Written for commit b7263f7. Summary will update on new commits.