Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const mainCommand = defineCommand({
description:
"Custom Authorization token to use for downloading template. (Can be overriden with `GIGET_AUTH` environment variable)",
},
authType: {
type: "string",
description: "Authorization type (can be `Basic` or `Bearer` by default)"
},
cwd: {
type: "string",
description:
Expand Down Expand Up @@ -76,6 +80,7 @@ const mainCommand = defineCommand({
offline: args.offline,
preferOffline: args.preferOffline,
auth: args.auth,
authType: args.authType,
install: args.install,
});

Expand Down
3 changes: 2 additions & 1 deletion src/giget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DownloadTemplateOptions {
registry?: false | string;
cwd?: string;
auth?: string;
authType?: string;
install?: boolean;
silent?: boolean;
}
Expand Down Expand Up @@ -69,7 +70,7 @@ export async function downloadTemplate(
throw new Error(`Unsupported provider: ${providerName}`);
}
const template = await Promise.resolve()
.then(() => provider(source, { auth: options.auth }))
.then(() => provider(source, { auth: options.auth, authType: options.authType }))
.catch((error) => {
throw new Error(
`Failed to download template from ${providerName}: ${error.message}`,
Expand Down
4 changes: 3 additions & 1 deletion src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ export const gitlab: TemplateProvider = (input, options) => {

export const bitbucket: TemplateProvider = (input, options) => {
const parsed = parseGitURI(input);
const bearerAuth = options.auth ? `Bearer ${options.auth}` : undefined
const basicAuth = options.auth ? `Basic ${Buffer.from(options.auth, 'utf8').toString('base64')}` : undefined
return {
name: parsed.repo.replace("/", "-"),
version: parsed.ref,
subdir: parsed.subdir,
headers: {
authorization: options.auth ? `Bearer ${options.auth}` : undefined,
authorization: options.authType === 'Basic' ? basicAuth : bearerAuth,
},
url: `https://bitbucket.com/${parsed.repo}/src/${parsed.ref}${parsed.subdir}`,
tar: `https://bitbucket.org/${parsed.repo}/get/${parsed.ref}.tar.gz`,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export interface TemplateInfo {

export type TemplateProvider = (
input: string,
options: { auth?: string },
options: { auth?: string, authType?: string },
) => TemplateInfo | Promise<TemplateInfo> | null;