Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For known dev sites, use LAST_LANGUAGE keyword #276

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions src/utils/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ const GitHub: HeartbeatParser = (url: string) => {

if (hostname.endsWith('.dev')) {
return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
};
}

const repo = document
.querySelector('meta[name=octolytics-dimension-repository_nwo]')
?.getAttribute('content');
if (repo?.split('/')[1] !== match[0]) return;
if (repo?.split('/')[1] !== match[0]) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

// TODO: parse language associated with this repo from the DOM
// TODO: parse branch associated with the PR url from the DOM
Expand All @@ -83,7 +88,7 @@ const GitHub: HeartbeatParser = (url: string) => {

return {
category,
language: githubLanguage(),
language: githubLanguage() ?? '<<LAST_LANGUAGE>>',
project: match[0],
};
};
Expand All @@ -93,9 +98,14 @@ const GitLab: HeartbeatParser = (url: string) => {
if (!match) return;

const repoName = document.querySelector('body')?.getAttribute('data-project-full-path');
if (!repoName || repoName.split('/')[1] !== match[0]) return;
if (!repoName || repoName.split('/')[1] !== match[0]) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
};
};
Expand All @@ -107,9 +117,14 @@ const BitBucket: HeartbeatParser = (url: string) => {
// this regex extracts the project name from the title
// eg. title: jhondoe / my-test-repo — Bitbucket
const match2 = document.querySelector('title')?.textContent?.match(/(?<=\/\s)([^/\s]+)(?=\s—)/);
if (!match2 || match2[0] !== match[0]) return;
if (!match2 || match2[0] !== match[0]) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
};
};
Expand All @@ -119,9 +134,14 @@ const TravisCI: HeartbeatParser = (url: string) => {
if (!match) return;

const projectName = document.querySelector('#ember737')?.textContent;
if (projectName !== match[0]) return;
if (projectName !== match[0]) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

return {
language: '<<LAST_LANGUAGE>>',
project: match[0],
};
};
Expand All @@ -139,7 +159,10 @@ const CircleCI: HeartbeatParser = (url: string) => {
'#__next > div:nth-child(2) > div > div > main > div > header > div:nth-child(1) > ol > li:nth-child(2) > div > span',
)?.textContent;
if (seconndBreadcrumbLabel === 'Project' && seconndBreadcrumbValue === projectPageMatch[0]) {
return { project: projectPageMatch[0] };
return {
language: '<<LAST_LANGUAGE>>',
project: projectPageMatch[0],
};
}
}

Expand All @@ -154,11 +177,16 @@ const CircleCI: HeartbeatParser = (url: string) => {
'#__next > div > div:nth-child(1) > header > div > div:nth-child(2) > div',
)?.textContent;
if (pageTitle === 'Project Settings' && pageSubtitle === settingsPageMatch[0]) {
return { project: settingsPageMatch[0] };
return {
language: '<<LAST_LANGUAGE>>',
project: settingsPageMatch[0],
};
}
}

return undefined;
return {
language: '<<LAST_LANGUAGE>>',
};
};

const Vercel: HeartbeatParser = (url: string) => {
Expand All @@ -168,16 +196,27 @@ const Vercel: HeartbeatParser = (url: string) => {
// this regex extracts the project name from the title
// eg. title: test-website - Overview – Vercel
const match2 = document.querySelector('title')?.textContent?.match(/^[^\s]+(?=\s-\s)/);
if (!match2 || match2[0] !== match[0]) return;
if (!match2 || match2[0] !== match[0]) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

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

const StackOverflow: HeartbeatParser = (_url: string) => {
const tags = Array.from(document.querySelectorAll('.post-tag').values())
.map((el) => el.textContent)
.filter(Boolean) as string[];
if (tags.length === 0) return;
if (tags.length === 0) {
return {
language: '<<LAST_LANGUAGE>>',
};
}

const languages = Array.from(document.querySelectorAll('code[data-highlighted="yes"]').values())
.map((code) => {
Expand All @@ -192,7 +231,9 @@ const StackOverflow: HeartbeatParser = (_url: string) => {
}
}

return undefined;
return {
language: '<<LAST_LANGUAGE>>',
};
};

const Canva: HeartbeatParser = (_url: string): OptionalHeartbeat | undefined => {
Expand Down
Loading