chore: send project on heartbeat when navigating on github (#165)

* chore: send project on heartbeat payload when user is navigating on github.com or github.dev

* chore: update logic to generate project from github activity

* chore: update history and development documentation

* chore: address comments in PR
This commit is contained in:
Juan Sebastian velez Posada
2023-02-10 11:04:49 -05:00
committed by GitHub
parent 78e298c4e4
commit be368b520e
4 changed files with 51 additions and 6 deletions

View File

@@ -89,11 +89,15 @@ class WakaTimeCore {
return changeExtensionState('blacklisted');
}
}
// Checks dev websites
const project = this.generateProjectFromDevSites(currentActiveTab.url as string);
if (items.loggingStyle == 'blacklist') {
if (!contains(currentActiveTab.url as string, items.blacklist as string)) {
await this.sendHeartbeat(
{
project: null,
project,
url: currentActiveTab.url as string,
},
apiKey,
@@ -110,7 +114,10 @@ class WakaTimeCore {
items.whitelist as string,
);
if (heartbeat.url) {
await this.sendHeartbeat(heartbeat, apiKey);
await this.sendHeartbeat(
{ ...heartbeat, project: heartbeat.project ?? project },
apiKey,
);
} else {
await changeExtensionState('whitelisted');
console.log(`${currentActiveTab.url} is not on a whitelist.`);
@@ -221,6 +228,17 @@ class WakaTimeCore {
return items.loggingType;
}
generateProjectFromDevSites(url: string): string | null {
const githubUrls = ['https://github.com/', 'https://github.dev/'];
for (const githubUrl of githubUrls) {
if (url.startsWith(githubUrl)) {
const newUrl = url.replace(githubUrl, '');
return newUrl.split('/')[1] || null;
}
}
return null;
}
/**
* Creates payload for the heartbeat and returns it as JSON.
*