diff --git a/src/core/WakaTimeCore.ts b/src/core/WakaTimeCore.ts index 266a875..67f3e44 100644 --- a/src/core/WakaTimeCore.ts +++ b/src/core/WakaTimeCore.ts @@ -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_EDGE, IS_FIREFOX, generateProjectFromDevSites } from '../utils'; +import { IS_EDGE, IS_FIREFOX, generateProjectFromDevSites, isCodeReviewing } from '../utils'; import { getApiKey } from '../utils/apiKey'; import changeExtensionState from '../utils/changeExtensionState'; import contains from '../utils/contains'; @@ -112,7 +112,7 @@ class WakaTimeCore { * Depending on various factors detects the current active tab URL or domain, * and sends it to WakaTime for logging. */ - async recordHeartbeat(payload = {}): Promise { + async recordHeartbeat(payload: Record = {}): Promise { const apiKey = await getApiKey(); if (!apiKey) { return changeExtensionState('notLogging'); @@ -166,6 +166,12 @@ class WakaTimeCore { // Checks dev websites const project = generateProjectFromDevSites(url); + // Check if code reviewing + const codeReviewing = isCodeReviewing(url); + if (codeReviewing) { + payload.category = 'code reviewing'; + } + if (items.loggingStyle == 'blacklist') { if (!contains(url, items.blacklist as string)) { await this.sendHeartbeat( diff --git a/src/utils/index.ts b/src/utils/index.ts index 2b65339..11217c9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -29,3 +29,14 @@ export const generateProjectFromDevSites = (url: string): string | null => { return match?.[0] ?? null; }; + +const CODE_REVIEW_URL_REG_LIST = [/github.com\/[^/]+\/[^/]+\/pull\/\d+\/files/]; + +export const isCodeReviewing = (url: string): boolean => { + for (const reg of CODE_REVIEW_URL_REG_LIST) { + if (url.match(reg)) { + return true; + } + } + return false; +};