-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: allow Drips Projects URL as input in list editor
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} |