Support self-hosted GitLab, get GitLab repo name from subgroups

This commit is contained in:
vlack
2024-10-04 00:31:35 +03:00
parent 46a1d3b867
commit 87e57c0056

View File

@@ -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: '<<LAST_LANGUAGE>>',
};
@@ -106,7 +108,7 @@ const GitLab: HeartbeatParser = (url: string) => {
return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
project: urlRepo,
};
};
@@ -368,7 +370,7 @@ const SITES: Record<KnownSite, SiteParser> = {
},
gitlab: {
parser: GitLab,
urls: [/^https?:\/\/(.+\.)?gitlab.com\//],
urls: [/^https?:\/\/(.+\.)?gitlab.[\w.]+\//],
},
googlemeet: {
parser: GoogleMeet,