From 87e57c0056a311a8dc5627f6584bc057cdc8fb7b Mon Sep 17 00:00:00 2001 From: vlack Date: Fri, 4 Oct 2024 00:31:35 +0300 Subject: [PATCH] Support self-hosted GitLab, get GitLab repo name from subgroups --- src/utils/sites.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utils/sites.ts b/src/utils/sites.ts index 8b14007..c6bbe08 100644 --- a/src/utils/sites.ts +++ b/src/utils/sites.ts @@ -94,11 +94,13 @@ const GitHub: HeartbeatParser = (url: string) => { }; const GitLab: HeartbeatParser = (url: string) => { - const match = url.match(/(?<=gitlab\.com\/[^/]+\/)([^/?#]+)/); + const match = url.match(/([^/]+)(?:\/-\/|\/?$)/); if (!match) return; + const urlRepo = match[1]; const repoName = document.querySelector('body')?.getAttribute('data-project-full-path'); - if (!repoName || repoName.split('/')[1] !== match[0]) { + const isValidPath = repoName?.split('/').pop() === urlRepo; + if (!isValidPath) { return { language: '<>', }; @@ -106,7 +108,7 @@ const GitLab: HeartbeatParser = (url: string) => { return { language: '<>', - project: match[0], + project: urlRepo, }; }; @@ -368,7 +370,7 @@ const SITES: Record = { }, gitlab: { parser: GitLab, - urls: [/^https?:\/\/(.+\.)?gitlab.com\//], + urls: [/^https?:\/\/(.+\.)?gitlab.[\w.]+\//], }, googlemeet: { parser: GoogleMeet,