From 967f90fc9a6535c2e687ba8367b53e81ee439202 Mon Sep 17 00:00:00 2001 From: hywax Date: Sun, 20 Oct 2024 15:42:16 +0500 Subject: [PATCH 1/2] feat: support `GIGET_BITBUCKET_URL` env variable --- src/providers.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/providers.ts b/src/providers.ts index ba8ce43..099d3a8 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -102,6 +102,9 @@ export const gitlab: TemplateProvider = (input, options) => { export const bitbucket: TemplateProvider = (input, options) => { const parsed = parseGitURI(input); + const bitbucketURL = + process.env.GIGET_BITBUCKET_URL || "https://bitbucket.org"; + return { name: parsed.repo.replace("/", "-"), version: parsed.ref, @@ -109,8 +112,8 @@ export const bitbucket: TemplateProvider = (input, options) => { headers: { authorization: options.auth ? `Bearer ${options.auth}` : undefined, }, - url: `https://bitbucket.com/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`, - tar: `https://bitbucket.org/${parsed.repo}/get/${parsed.ref}.tar.gz`, + url: `${bitbucketURL}/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`, + tar: `${bitbucketURL}/${parsed.repo}/get/${parsed.ref}.tar.gz`, }; }; From ca984a1d183666897908ae409f19db2e1677a4cc Mon Sep 17 00:00:00 2001 From: hywax Date: Sun, 20 Oct 2024 16:17:14 +0500 Subject: [PATCH 2/2] feat: self-hosted Bitbucket paths --- src/providers.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/providers.ts b/src/providers.ts index 099d3a8..8787c8b 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -105,6 +105,21 @@ export const bitbucket: TemplateProvider = (input, options) => { const bitbucketURL = process.env.GIGET_BITBUCKET_URL || "https://bitbucket.org"; + let paths: Pick = { + url: `${bitbucketURL}/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`, + tar: `${bitbucketURL}/${parsed.repo}/get/${parsed.ref}.tar.gz`, + }; + + // Self-hosted Bitbucket paths + if (bitbucketURL !== "https://bitbucket.org") { + const [project, repo] = parsed.repo.split("/"); + + paths = { + url: `${bitbucketURL}/projects/${project}/repos/${repo}/browse${parsed.subdir}?at=${parsed.ref}`, + tar: `${bitbucketURL}/rest/api/latest/projects/${project}/repos/${repo}/archive?at=${parsed.ref}&format=tar.gz`, + }; + } + return { name: parsed.repo.replace("/", "-"), version: parsed.ref, @@ -112,8 +127,7 @@ export const bitbucket: TemplateProvider = (input, options) => { headers: { authorization: options.auth ? `Bearer ${options.auth}` : undefined, }, - url: `${bitbucketURL}/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`, - tar: `${bitbucketURL}/${parsed.repo}/get/${parsed.ref}.tar.gz`, + ...paths, }; };