diff --git a/src/lib/components/list-editor/components/list-editor-input.svelte b/src/lib/components/list-editor/components/list-editor-input.svelte index 93bf8ac4d..f0c172d03 100644 --- a/src/lib/components/list-editor/components/list-editor-input.svelte +++ b/src/lib/components/list-editor/components/list-editor-input.svelte @@ -26,6 +26,7 @@ import List from '$lib/components/icons/List.svelte'; import ExclamationCircle from '$lib/components/icons/ExclamationCircle.svelte'; import { slide } from 'svelte/transition'; + import { buildRepositoryURL, isDripsProjectUrl } from '$lib/utils/build-repo-url'; const dispatch = createEventDispatcher<{ addAddress: { accountId: string; address: string }; @@ -55,7 +56,7 @@ }); $: validInput = - (allowProjects && isSupportedGitUrl(inputValue)) || + (allowProjects && (isSupportedGitUrl(inputValue) || isDripsProjectUrl(inputValue))) || (allowAddresses && (inputValue.endsWith('.eth') || isAddress(inputValue))) || (allowDripLists && inputValue.includes(`${BASE_URL}/app/drip-lists/`)); @@ -75,6 +76,10 @@ } } + async function addDripsProject(urlValue: string) { + return addProject(buildRepositoryURL(urlValue)); + } + async function addProject(urlValue: string) { let url = urlValue; @@ -239,6 +244,8 @@ await addAddress(value); } else if (value.includes(`${BASE_URL}/app/drip-lists/`)) { await addDripList(value); + } else if (value.includes(`${BASE_URL}/app/projects/`)) { + await addDripsProject(value); } } catch (e) { if (e instanceof AddItemError) { diff --git a/src/lib/utils/build-repo-url.ts b/src/lib/utils/build-repo-url.ts new file mode 100644 index 000000000..e136a7872 --- /dev/null +++ b/src/lib/utils/build-repo-url.ts @@ -0,0 +1,38 @@ +import { BASE_URL } from './base-url'; +import { isValidGitUrl } from './is-valid-git-url'; + +export function isDripsProjectUrl(value: string): boolean { + return value.includes(`${BASE_URL}/app/projects/`); +} + +export function buildRepositoryURL(url: string): string { + const parsedUrl = new URL(url); + const pathSegments = parsedUrl.pathname.split('/').filter((segment) => segment.length > 0); + + const forgeIndex = pathSegments.findIndex((segment) => + ['github', 'gitlab', 'bitbucket'].includes(segment), + ); + + if (forgeIndex !== -1) { + const forge = pathSegments[forgeIndex]; + const repoPath = pathSegments.slice(forgeIndex + 1).join('/'); + + if (!repoPath) { + throw new Error('Repository path is incomplete.'); + } + + if (forge === 'github') { + const githubUrl = `https://github.com/${repoPath}`; + + if (isValidGitUrl(githubUrl)) { + return `https://github.com/${repoPath}`; + } + + throw new Error(`Invalid GitHub URL: ${githubUrl}.`); + } else { + throw new Error(`Unsupported forge: ${forge}.`); + } + } + + throw new Error('Forge not found in the URL path.'); +}