fix: read footer commit count from the GitHub API on Vercel - #74
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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), sogit fetch --unshallowfailed silently and fell back to the shallow count. My localfile://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: theLinkheader'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.VERCEL_GIT_REPO_OWNER/SLUG(fallbackRECTOR-LABS/core); ref is the deployed SHA.Verification
?sha=main)git rev-list --countlint clean; 50 version tests pass. Final confirmation will be the live footer after deploy.