Skip to content

Commit

Permalink
Support self-hosted GitLab, get GitLab repo name from subgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ack committed Oct 3, 2024
1 parent 46a1d3b commit 87e57c0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ 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>>',
};
}

return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
project: urlRepo,
};
};

Expand Down Expand Up @@ -368,7 +370,7 @@ const SITES: Record<KnownSite, SiteParser> = {
},
gitlab: {
parser: GitLab,
urls: [/^https?:\/\/(.+\.)?gitlab.com\//],
urls: [/^https?:\/\/(.+\.)?gitlab.[\w.]+\//],
},
googlemeet: {
parser: GoogleMeet,
Expand Down

0 comments on commit 87e57c0

Please sign in to comment.