Merge pull request #262 from wakatime/fix-47

Set project based on URL when browsing GitHub, Waffle.io, CircleCi, etc #47
This commit is contained in:
Alan Hamlett
2024-08-19 13:33:40 +02:00
committed by GitHub

View File

@@ -2,15 +2,30 @@ export const IS_EDGE = navigator.userAgent.includes('Edg');
export const IS_FIREFOX = navigator.userAgent.includes('Firefox'); export const IS_FIREFOX = navigator.userAgent.includes('Firefox');
export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false; export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false;
export const generateProjectFromDevSites = (siteUrl: string): string | null => { const REG_LIST = [
const url = new URL(siteUrl); // GitHub. Eg. URL: https://github.com/workspace-name/project-name
const githubUrls = ['github.com', 'github.dev']; /(?<=github\.(?:com|dev)\/[^/]+\/)([^/?#]+)/,
for (const githubUrl of githubUrls) { // Gitlab. Eg. URL: https://gitlab.com/workspace-name/project-name
if (url.host === githubUrl) { /(?<=gitlab\.com\/[^/]+\/)([^/?#]+)/,
// input: https://github.com/wakatime/browser-wakatime?tab=readme-ov-file#development-instructions // BitBucket. Eg. URL: https://bitbucket.org/workspace-name/project-name/src
// output: browser-wakatime /(?<=bitbucket\.org\/[^/]+\/)([^/?#]+)/,
return url.pathname.split('/')[2] || null; // Travis CI. Eg. URL: https://app.travis-ci.com/github/workspace-name/project-name/no-build?serverType=git
/(?<=app\.travis-ci\.com\/[^/]+\/[^/]+\/)([^/?#]+)/,
// Circle CI. Eg. URL: https://app.circleci.com/projects/project-setup/github/workspace-name/project-name/
/(?<=app\.circleci\.com\/projects\/[^/]+\/[^/]+\/[^/]+\/)([^/?#]+)/,
// Vercel. Eg. URL: http://vercel.com/team-name/project-name
/(?<=vercel\.com\/[^/]+\/)([^/?#]+)/,
];
export const generateProjectFromDevSites = (url: string): string | null => {
let match: RegExpMatchArray | null = null;
for (const reg of REG_LIST) {
match = url.match(reg);
if (match) {
break;
} }
} }
return null;
return match?.[0] ?? null;
}; };