From 8c4bebc48642c44b68a4c188bf48215e72bacac5 Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 21 Oct 2024 20:27:07 -0300 Subject: [PATCH] Allow to use a github url as extension --- src/utils/external-extensions.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/utils/external-extensions.ts b/src/utils/external-extensions.ts index 376726d46..d1b996e6c 100644 --- a/src/utils/external-extensions.ts +++ b/src/utils/external-extensions.ts @@ -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;