@samitouri / QOSami-HFS / commits / e8f00485

avoid consuming github's api quota on bad repos

Massimo Melina committed Sep 30, 2024 at 18:41 UTC e8f00485109c333b6ba7efd9ebbe99c319b8fc63
1 file changed +7 -1
src/github.ts
+7 -1
@@ -32,7 +32,13 @@ function downloadProgress(repo: string, status: DownloadStatus) {
32
33 // determine default branch, possibly without consuming api quota
34 async function getGithubDefaultBranch(repo: string) {
35 - const test = await httpString(`https://github.com/${repo}/archive/refs/heads/main.zip`, { method: 'HEAD' }).then(() => 1, () => 0)
35 + if (!repo.includes('/'))
36 + throw 'malformed repo'
37 + const test = await httpString(`https://github.com/${repo}/archive/refs/heads/main.zip`, { method: 'HEAD' }).then(() => 1, (err) => {
38 + if (err?.cause?.statusCode === 404)
39 + throw err
40 + return 0
41 + })
42 return test ? 'main' : (await getRepoInfo(repo))?.default_branch as string
43 }
44