Merge pull request #258 from wakatime/fix-251

fix: strip hash and search from project name #251
This commit is contained in:
Alan Hamlett
2024-08-15 21:31:22 +02:00
committed by GitHub
6 changed files with 57 additions and 2852 deletions

View File

@@ -1,7 +1,7 @@
@import 'node_modules/bootswatch/dist/materia/_variables';
@import 'node_modules/bootstrap/scss/bootstrap';
@import 'node_modules/bootswatch/dist/materia/_bootswatch';
@import 'node_modules/font-awesome/scss/font-awesome';
@import 'bootswatch/dist/materia/_variables';
@import 'bootstrap/scss/bootstrap';
@import 'bootswatch/dist/materia/_bootswatch';
@import 'font-awesome/scss/font-awesome';
@import 'variables';
@import 'partials/_animations';

2873
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -102,12 +102,11 @@
"lint-staged": "^13.1.0",
"mocha": "^10.2.0",
"mocha-sinon": "^2.1.2",
"node-gyp": "^8.3.0",
"node-sass": "^8.0.0",
"prettier": "^2.8.2",
"prettier-plugin-packagejson": "^2.3.0",
"prettier-plugin-sort-json": "1.0.0",
"rimraf": "^3.0.2",
"sass": "^1.77.8",
"shelljs": "^0.8.5",
"sinon": "^15.0.1",
"sinon-chai": "^3.7.0",

View File

@@ -8,7 +8,7 @@ import config from '../config/config';
import { SendHeartbeat } from '../types/heartbeats';
import { GrandTotal, SummariesPayload } from '../types/summaries';
import { ApiKeyPayload, AxiosUserResponse, User } from '../types/user';
import { IS_FIREFOX, IS_EDGE, generateProjectFromDevSites } from '../utils';
import { IS_EDGE, IS_FIREFOX, generateProjectFromDevSites } from '../utils';
import { getApiKey } from '../utils/apiKey';
import changeExtensionState from '../utils/changeExtensionState';
import contains from '../utils/contains';
@@ -170,6 +170,7 @@ class WakaTimeCore {
if (!contains(url, items.blacklist as string)) {
await this.sendHeartbeat(
{
branch: null,
hostname: items.hostname as string,
project,
url,
@@ -189,6 +190,7 @@ class WakaTimeCore {
await this.sendHeartbeat(
{
...heartbeat,
branch: null,
hostname: items.hostname as string,
project: heartbeat.project ?? project,
},
@@ -285,6 +287,7 @@ class WakaTimeCore {
apiKey: string,
navigationPayload: Record<string, unknown>,
): Promise<void> {
console.log('Sending Heartbeat', heartbeat);
let payload;
const loggingType = await this.getLoggingType();
@@ -339,12 +342,12 @@ class WakaTimeCore {
let userAgent;
if (IS_FIREFOX) {
browserName = 'firefox';
userAgent = navigator.userAgent.match(/Firefox\/\S+/g)![0];
userAgent = navigator.userAgent.match(/Firefox\/\S+/g)?.[0];
} else if (IS_EDGE) {
browserName = 'edge';
userAgent = navigator.userAgent;
} else {
userAgent = navigator.userAgent.match(/Chrome\/\S+/g)![0];
userAgent = navigator.userAgent.match(/Chrome\/\S+/g)?.[0];
}
const payload: Record<string, unknown> = {
entity: heartbeat.url,

View File

@@ -2,12 +2,14 @@ export const IS_EDGE = navigator.userAgent.includes('Edg');
export const IS_FIREFOX = navigator.userAgent.includes('Firefox');
export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false;
export const generateProjectFromDevSites = (url: string): string | null => {
const githubUrls = ['https://github.com/', 'https://github.dev/'];
export const generateProjectFromDevSites = (siteUrl: string): string | null => {
const url = new URL(siteUrl);
const githubUrls = ['github.com', 'github.dev'];
for (const githubUrl of githubUrls) {
if (url.startsWith(githubUrl)) {
const newUrl = url.replace(githubUrl, '');
return newUrl.split('/')[1] || null;
if (url.host === githubUrl) {
// input: https://github.com/wakatime/browser-wakatime?tab=readme-ov-file#development-instructions
// output: browser-wakatime
return url.pathname.split('/')[2] || null;
}
}
return null;

View File

@@ -78,15 +78,15 @@ load({
),
),
],
'build-sass': exec('sass assets/sass/app.scss public/css/app.css --load-path=node_modules'),
clean: [exec('rimraf public coverage vendor web-ext-artifacts'), 'clean:webpack'],
'clean:webpack': exec('rimraf dist'),
dev: ['clean', 'postinstall', concurrent('watch', 'web-ext:run:firefox', 'web-ext:run:chrome')],
eslint: exec('eslint src . --fix'),
lint: ['prettier', 'eslint'],
postinstall: ['clean', makePublicFolder, copyFromNodeModules, 'sass'],
postinstall: ['clean', makePublicFolder, copyFromNodeModules, 'build-sass'],
prettier: [exec('prettier --write .')],
'remotedev-server': exec('remotedev --hostname=localhost --port=8000'),
sass: exec('node-sass assets/sass/app.scss public/css/app.css'),
test: ['build', 'lint', 'test-jest'],
'test-jest': [exec('jest --clearCache'), exec('jest --verbose --coverage')],
watch: concurrent('watch-jest', 'webpack:watch'),