From 274a660369f429e3e86777711e1222644fb86128 Mon Sep 17 00:00:00 2001 From: Rohid Date: Mon, 19 Aug 2024 15:12:25 +0600 Subject: [PATCH] extract project name from gitlab --- src/utils/index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 9b88e46..1ff6cf9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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; };