Skip to content

Commit 65564a5

Browse files
committed
fix(docs): fetch commit history from the repository Vercel names, since its clone has no origin remote
1 parent 7e8a98e commit 65564a5

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

‎apps/docs/scripts/fetch-git-history.ts‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* shallow clone (every file untouched since the boundary commit would get that commit's date), so
44
* the docs sitemap shipped with no `lastModified` at all. Fetch the commit history before the
55
* build. `--filter=blob:none` skips file contents: `git log --name-only` needs commits and trees.
6+
* Vercel's clone has no `origin` remote, so the history comes from the public repository URL its
7+
* system environment names, pinned to the commit being built.
68
*
79
* A failed fetch leaves the clone shallow, so pages ship undated as before. That is logged rather
810
* than failing the deploy, because dates are an enhancement and the docs must still ship.
@@ -25,10 +27,37 @@ function git(args: string[], timeout?: number): string {
2527
}).trim()
2628
}
2729

28-
if (process.env.VERCEL) {
30+
const {
31+
VERCEL,
32+
VERCEL_GIT_PROVIDER,
33+
VERCEL_GIT_REPO_OWNER,
34+
VERCEL_GIT_REPO_SLUG,
35+
VERCEL_GIT_COMMIT_SHA,
36+
} = process.env
37+
38+
if (VERCEL) {
2939
try {
3040
if (git(['rev-parse', '--is-shallow-repository']) === 'true') {
31-
git(['fetch', '--unshallow', '--filter=blob:none', '--no-tags', 'origin'], FETCH_TIMEOUT_MS)
41+
if (
42+
VERCEL_GIT_PROVIDER !== 'github' ||
43+
!VERCEL_GIT_REPO_OWNER ||
44+
!VERCEL_GIT_REPO_SLUG ||
45+
!VERCEL_GIT_COMMIT_SHA
46+
) {
47+
throw new Error('Vercel did not provide the GitHub repository and commit for this build')
48+
}
49+
const repositoryUrl = `https://github.com/${VERCEL_GIT_REPO_OWNER}/${VERCEL_GIT_REPO_SLUG}.git`
50+
git(
51+
[
52+
'fetch',
53+
'--unshallow',
54+
'--filter=blob:none',
55+
'--no-tags',
56+
repositoryUrl,
57+
VERCEL_GIT_COMMIT_SHA,
58+
],
59+
FETCH_TIMEOUT_MS
60+
)
3261
logger.info('Fetched full commit history for docs last-modified dates')
3362
} else {
3463
logger.info('Clone already has full commit history')

0 commit comments

Comments
 (0)