From 8c4bebc48642c44b68a4c188bf48215e72bacac5 Mon Sep 17 00:00:00 2001 From: Damian Date: Mon, 21 Oct 2024 20:27:07 -0300 Subject: [PATCH 1/4] 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; From 5666726c51f2f39ab937be5038e364011bf00c89 Mon Sep 17 00:00:00 2001 From: Damian Date: Fri, 27 Dec 2024 12:07:27 -0300 Subject: [PATCH 2/4] Add deconstructGithubUrl function --- src/utils/external-extensions.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/utils/external-extensions.ts b/src/utils/external-extensions.ts index d1b996e6c..5a454da3e 100644 --- a/src/utils/external-extensions.ts +++ b/src/utils/external-extensions.ts @@ -4,6 +4,16 @@ import { fileURLToPath } from "url"; import { ExternalExtension, RawOptions, SolidityFramework } from "../types"; import { CURATED_EXTENSIONS } from "../curated-extensions"; import { SOLIDITY_FRAMEWORKS } from "./consts"; + +function deconstructGithubUrl(url: string) { + const urlParts = url.split("/"); + const ownerName = urlParts[3]; + const repoName = urlParts[4]; + const branch = urlParts[5] === "tree" ? urlParts[6] : undefined; + + return { ownerName, repoName, branch }; +} + // Gets the data from the argument passed to the `--extension` option. // e.g. owner/project:branch => { githubBranchUrl, githubUrl, branch, owner, project } export const getDataFromExternalExtensionArgument = (externalExtension: string) => { @@ -24,10 +34,10 @@ export const getDataFromExternalExtensionArgument = (externalExtension: string) 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]; + const { ownerName, repoName, branch: urlBranch } = deconstructGithubUrl(externalExtension); + owner = ownerName; + project = repoName; + branch = urlBranch; } else { // Extract owner, project and branch from owner/project:branch owner = externalExtension.split("/")[0]; @@ -85,9 +95,7 @@ export const getSolidityFrameworkDirsFromExternalExtension = async ( } const { branch, repository } = externalExtension; - const splitUrl = repository.split("/"); - const ownerName = splitUrl[splitUrl.length - 2]; - const repoName = splitUrl[splitUrl.length - 1]; + const { ownerName, repoName } = deconstructGithubUrl(repository); const githubApiUrl = `https://api.github.com/repos/${ownerName}/${repoName}/contents/extension/packages${branch ? `?ref=${branch}` : ""}`; const res = await fetch(githubApiUrl); if (!res.ok) { From 0df5d075cd07bb8b1ee8712f1238c54f5b555060 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Mon, 30 Dec 2024 10:47:35 +0530 Subject: [PATCH 3/4] minor tweak to comment --- src/utils/external-extensions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/external-extensions.ts b/src/utils/external-extensions.ts index 5a454da3e..504a70905 100644 --- a/src/utils/external-extensions.ts +++ b/src/utils/external-extensions.ts @@ -15,7 +15,6 @@ function deconstructGithubUrl(url: string) { } // Gets the data from the argument passed to the `--extension` option. -// e.g. owner/project:branch => { githubBranchUrl, githubUrl, branch, owner, project } export const getDataFromExternalExtensionArgument = (externalExtension: string) => { if (CURATED_EXTENSIONS[externalExtension.toLowerCase()]) { externalExtension = getArgumentFromExternalExtensionOption(CURATED_EXTENSIONS[externalExtension]); @@ -39,7 +38,7 @@ export const getDataFromExternalExtensionArgument = (externalExtension: string) project = repoName; branch = urlBranch; } else { - // Extract owner, project and branch from owner/project:branch + // Extract owner, project and branch if format passed is owner/project:branch owner = externalExtension.split("/")[0]; project = externalExtension.split(":")[0].split("/")[1]; branch = externalExtension.split(":")[1]; From aaa7ef6695e1429dffd5a2775644dca6cd20cca4 Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Mon, 30 Dec 2024 10:49:38 +0530 Subject: [PATCH 4/4] add changeset --- .changeset/two-points-cheer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-points-cheer.md diff --git a/.changeset/two-points-cheer.md b/.changeset/two-points-cheer.md new file mode 100644 index 000000000..d41de5eb1 --- /dev/null +++ b/.changeset/two-points-cheer.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +cli: allow github url as extension flag