Skip to content

fix: read footer commit count from the GitHub API on Vercel - #74

Merged
rz1989s merged 1 commit into
mainfrom
fix/footer-commit-count-github-api
Jun 15, 2026
Merged

fix: read footer commit count from the GitHub API on Vercel#74
rz1989s merged 1 commit into
mainfrom
fix/footer-commit-count-github-api

Conversation

@rz1989s

@rz1989s rz1989s commented Jun 15, 2026

Copy link
Copy Markdown
Member

Follow-up to #72 — that fix didn't hold in production

After #72 merged, the live footer still showed "20 Commits" (the depth-10 shallow count) at sha a125d24. Root cause of the regression: Vercel's build sandbox has no fetchable git remote (credentials are stripped after the initial shallow clone), so git fetch --unshallow failed silently and fell back to the shallow count. My local file:// test couldn't catch this — a local clone has a working remote.

Proper fix — GitHub commits API

Resolve the count from GET /repos/{owner}/{repo}/commits?sha={ref}&per_page=1: the Link header's rel="last" page number is the true total. This needs only HTTPS to api.github.com — which the build already uses for the homepage repo cards — not a git remote, so it works in Vercel's sandbox.

  • Only runs when the checkout is shallow (Vercel). Full local clones keep the git count with no network call.
  • Repo slug from VERCEL_GIT_REPO_OWNER/SLUG (fallback RECTOR-LABS/core); ref is the deployed SHA.
  • Null-safe: any API failure falls back to the git count, so the build never breaks.

Verification

Scenario Before After
Local full clone 314 314 (git, no API call)
Simulated Vercel depth=10 shallow 20 314 (via API)
Live API cross-check (?sha=main) Link rel=last = 314 = git rev-list --count

lint clean; 50 version tests pass. Final confirmation will be the live footer after deploy.

The previous fix (git fetch --unshallow) worked locally but not in production: Vercel's build sandbox has no fetchable git remote (credentials are stripped after the shallow clone), so --unshallow failed silently and the footer still showed the depth-10 count ("20 Commits").

Resolve the count from the GitHub commits API instead — GET /repos/{owner}/{repo}/commits?sha={ref}&per_page=1 exposes the true total via the Link header's rel="last" page number. This needs only HTTPS to api.github.com (which the build already uses for the repo cards), not a git remote, so it works in Vercel's sandbox.

Only invoked when the checkout is shallow (Vercel); full local clones keep the git count with no network call. Null-safe: any API failure falls back to the git count, so the build never breaks.

Verified: a simulated depth=10 shallow clone resolves 314 (the true total) via the API instead of the shallow 20.
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
core Ready Ready Preview, Comment Jun 15, 2026 11:08pm

@rz1989s
rz1989s merged commit a836cbe into main Jun 15, 2026
3 checks passed
@rz1989s
rz1989s deleted the fix/footer-commit-count-github-api branch June 15, 2026 23:09
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.

1 participant