Skip to content

Commit

Permalink
Add GITHUB_TOKEN if available for all downloads
Browse files Browse the repository at this point in the history
This means we can fetch private pantry without git
  • Loading branch information
mxcl committed Sep 29, 2022
1 parent 061a972 commit aee8e00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Change how your team works.
 


# tea/cli 0.6.7
# tea/cli 0.6.8

tea is a universal virtual‑environment manager:

Expand Down
8 changes: 0 additions & 8 deletions src/hooks/useCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ const download = async (opts: DownloadOptions) => {
case 'src': {
const extname = new Path(url.pathname).extname()
dst = path({ pkg: opts.pkg, type: 'src', extname })

//FIXME: big hacks
if (opts.pkg.project === "tea.xyz" && url.host === "github.com") {
const token = Deno.env.get("GITHUB_TOKEN")
if (!token) { throw new Error("private repos require a GITHUB_TOKEN") }
headers["Authorization"] = `bearer ${token}`
}

} break
case 'script':
dst = undefined
Expand Down
10 changes: 9 additions & 1 deletion src/hooks/useDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async function download({ src, dst, headers, ephemeral }: DownloadOptions): Prom
dst ??= hash().join(src.path().basename())
if (src.protocol === "file:") throw new Error()


if (!ephemeral && mtime_entry().isFile() && dst.isReadableFile()) {
headers ??= {}
headers["If-Modified-Since"] = await mtime_entry().read()
Expand All @@ -33,6 +32,15 @@ async function download({ src, dst, headers, ephemeral }: DownloadOptions): Prom
console.info({downloading: src.toString()})
}

// so the user can add private repos if they need to etc.
if (/(^|\.)github.com$/.test(src.host)) {
const token = Deno.env.get("GITHUB_TOKEN")
if (token) {
headers ??= {}
headers["Authorization"] = `bearer ${token}`
}
}

const rsp = await fetch(src, {headers})

switch (rsp.status) {
Expand Down

0 comments on commit aee8e00

Please sign in to comment.