Skip to content

Commit

Permalink
Allow to use a github url as extension
Browse files Browse the repository at this point in the history
  • Loading branch information
damianmarti committed Oct 21, 2024
1 parent e950e6f commit 8c4bebc
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/utils/external-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ export const getDataFromExternalExtensionArgument = (externalExtension: string)
externalExtension = getArgumentFromExternalExtensionOption(CURATED_EXTENSIONS[externalExtension]);
}

const isGithubUrl = externalExtension.startsWith("https://github.com/");

// Check format: owner/project:branch (branch is optional)
const regex = /^[^/]+\/[^/]+(:[^/]+)?$/;
if (!regex.test(externalExtension)) {
throw new Error(`Invalid extension format. Use "owner/project" or "owner/project:branch"`);
if (!regex.test(externalExtension) && !isGithubUrl) {
throw new Error(`Invalid extension format. Use "owner/project", "owner/project:branch" or github url.`);
}

// Extract owner, project and branch
const owner = externalExtension.split("/")[0];
const project = externalExtension.split(":")[0].split("/")[1];
const branch = externalExtension.split(":")[1];
let owner;
let project;
let branch;

if (isGithubUrl) {
// Extract owner, project and branch from github url
owner = externalExtension.split("/")[3];
project = externalExtension.split("/")[4];
branch = externalExtension.split("/tree/")[1];
} else {
// Extract owner, project and branch from owner/project:branch
owner = externalExtension.split("/")[0];
project = externalExtension.split(":")[0].split("/")[1];
branch = externalExtension.split(":")[1];
}

const githubUrl = `https://github.com/${owner}/${project}`;
let githubBranchUrl;
Expand Down

0 comments on commit 8c4bebc

Please sign in to comment.