extract project name from gitlab

This commit is contained in:
Rohid
2024-08-19 15:12:25 +06:00
parent 0d0c89305d
commit 274a660369

View File

@@ -4,13 +4,26 @@ export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false;
export const generateProjectFromDevSites = (siteUrl: string): string | null => {
const url = new URL(siteUrl);
const githubUrls = ['github.com', 'github.dev'];
for (const githubUrl of githubUrls) {
if (url.host === githubUrl) {
// Github
const githubHosts = ['github.com', 'github.dev'];
for (const host of githubHosts) {
if (url.host === host) {
// input: https://github.com/wakatime/browser-wakatime?tab=readme-ov-file#development-instructions
// output: browser-wakatime
return url.pathname.split('/')[2] || null;
}
}
// Gitlab
const gitlabHosts = ['gitlab.com'];
for (const host of gitlabHosts) {
if (url.host === host) {
// input: https://gitlab.com/wakatime/browser-wakatime?tab=readme-ov-file#development-instructions
// output: browser-wakatime
return url.pathname.split('/')[2] || null;
}
}
return null;
};