Skip to content

Commit 5f6a415

Browse files
authored
feat(upgrade): Use GitHub token if available when downloading patches (#10515)
1 parent 0f62933 commit 5f6a415

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.changesets/10515.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- feat(upgrade): Use GitHub token if available when downloading patches (#10515) by @Tobbe
2+
3+
If a GitHub token is available in the environment we use that when fetching the
4+
git tree from GitHub. That way we're less likely to be rate limited. For most
5+
users the token shouldn't be needed. The free allowance/usage of the GitHub API
6+
should be enough.
7+
8+
We support `GH_TOKEN`, `GITHUB_TOKEN` and `REDWOOD_GITHUB_TOKEN` as the env var names

packages/cli/src/commands/upgrade.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,24 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
365365
throw new Error('Failed to upgrade')
366366
}
367367

368+
const githubToken =
369+
process.env.GH_TOKEN ||
370+
process.env.GITHUB_TOKEN ||
371+
process.env.REDWOOD_GITHUB_TOKEN
372+
368373
const res = await fetch(
369374
'https://api.github.com/repos/redwoodjs/redwood/git/trees/main?recursive=1',
375+
{
376+
headers: {
377+
Authorization: githubToken ? `Bearer ${githubToken}` : undefined,
378+
['X-GitHub-Api-Version']: '2022-11-28',
379+
Accept: 'application/vnd.github+json',
380+
},
381+
},
370382
)
383+
371384
const json = await res.json()
372-
const patches = json.tree.filter((patchInfo) =>
385+
const patches = json.tree?.filter((patchInfo) =>
373386
patchInfo.path.startsWith(
374387
'packages/create-redwood-app/templates/ts/.yarn/patches/',
375388
),
@@ -386,7 +399,7 @@ async function downloadYarnPatches(ctx, { dryRun, verbose }) {
386399
}
387400

388401
return new Listr(
389-
patches.map((patch) => {
402+
(patches || []).map((patch) => {
390403
return {
391404
title: `Downloading ${patch.path}`,
392405
task: async () => {

0 commit comments

Comments
 (0)