From 3d77e591d483d34d95125bfe2bcc58a7f7796f10 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Thu, 5 Oct 2023 00:56:41 +0530 Subject: [PATCH] fix(github): use `api.github.com` for private repository support (#93) Co-authored-by: Pooya Parsa --- src/providers.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/providers.ts b/src/providers.ts index bb5d8a9..4590f30 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -3,16 +3,24 @@ import { parseGitURI } from "./_utils"; export const github: TemplateProvider = (input, options) => { const parsed = parseGitURI(input); - const github = process.env.GIGET_GITHUB_URL || "https://github.com"; + + // https://docs.github.com/en/rest/repos/contents#download-a-repository-archive-tar + // TODO: Verify solution for github enterprise + const githubAPIURL = process.env.GIGET_GITHUB_URL || "https://api.github.com"; + return { name: parsed.repo.replace("/", "-"), version: parsed.ref, subdir: parsed.subdir, headers: { - authorization: options.auth ? `Bearer ${options.auth}` : undefined, + Authorization: options.auth ? `Bearer ${options.auth}` : undefined, + Accept: "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", }, - url: `${github}/${parsed.repo}/tree/${parsed.ref}${parsed.subdir}`, - tar: `${github}/${parsed.repo}/archive/${parsed.ref}.tar.gz`, + url: `${githubAPIURL.replace("api.github.com", "github.com")}/${ + parsed.repo + }/tree/${parsed.ref}${parsed.subdir}`, + tar: `${githubAPIURL}/repos/${parsed.repo}/tarball/${parsed.ref}`, }; };