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

@@ -6,8 +6,8 @@ We are currently migrating from using [gulp](https://gulpjs.com/) -> [webpack](h
## Pre-requisites
- node v11.15.0
- npm 6.7.0
- node v18.13.0
- npm 8.19.3
It is suggested you use [nvm](https://github.com/nvm-sh/nvm) to manage your node version
@@ -22,7 +22,7 @@ In devmode you can open [local remote devtools](http://localhost:8000)
## Development instructions
```
nvm use
nvm use 18
npm install
npm run dev
```

View File

@@ -3,6 +3,33 @@ History
-------
3.0.0 (2023-02-09)
++++++++++++++++++
- chore: send project on heartbeat when navigating on github
`#165 <https://github.com/wakatime/chrome-wakatime/pull/165>`_
- chore: add social media toggle to track or not social sites
`#163 <https://github.com/wakatime/chrome-wakatime/pull/163>`_
- implement service worker events
`#162 <https://github.com/wakatime/chrome-wakatime/pull/162>`_
- chore: Chrome Manifest V2 to V3 migration
`#161 <https://github.com/wakatime/chrome-wakatime/pull/161>`_
- chore: implements send Heartbeat functionality
`#160 <https://github.com/wakatime/chrome-wakatime/pull/160>`_
- chore: move api key input to options view
`#159 <https://github.com/wakatime/chrome-wakatime/pull/159>`_
- chore: update bootstrap to version 5
`#158 <https://github.com/wakatime/chrome-wakatime/pull/158>`_
- chore: implement options component
`#157 <https://github.com/wakatime/chrome-wakatime/pull/157>`_
- chore: enable disable logging
`#156 <https://github.com/wakatime/chrome-wakatime/pull/156>`_
- chore: implement new ts components
`#155 <https://github.com/wakatime/chrome-wakatime/pull/155>`_
- chore: update dependencies
`#153 <https://github.com/wakatime/chrome-wakatime/pull/153>`_
2.0.1 (2021-01-11)
++++++++++++++++++

View File

@@ -39,5 +39,5 @@
"storage",
"idle"
],
"version": "2.0.1"
"version": "3.0.0"
}

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.
*