Skip to content

Commit 1403a4d

Browse files
authored
Merge pull request #96 from wakatime/bugfix/project-names
Fix parsing project from browser url
2 parents 082213e + f7c75d8 commit 1403a4d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

electron/helpers/monitored-app.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,30 @@ export class MonitoredApp {
103103
return null;
104104
}
105105
const patterns = [
106-
/github\.com\/([^/]+\/[^/]+)\/?.*$/,
107-
/bitbucket\.org\/([^/]+\/[^/]+)\/?.*$/,
108-
/app\.circleci\.com\/.*\/?(github|bitbucket|gitlab)\/([^/]+\/[^/]+)\/?.*$/,
109-
/app\.travis-ci\.com\/(github|bitbucket|gitlab)\/([^/]+\/[^/]+)\/?.*$/,
110-
/app\.travis-ci\.org\/(github|bitbucket|gitlab)\/([^/]+\/[^/]+)\/?.*$/,
106+
{ expression: /github\.com\/[^/]+\/([^/]+)\/?.*$/, group: 1 },
107+
{ expression: /gitlab\.com\/[^/]+\/([^/]+)\/?.*$/, group: 1 },
108+
{ expression: /bitbucket\.org\/[^/]+\/([^/]+)\/?.*$/, group: 1 },
109+
{
110+
expression:
111+
/app\.circleci\.com\/.*\/?(github|bitbucket|gitlab)\/[^/]+\/([^/]+)\/?.*$/,
112+
group: 2,
113+
},
114+
{
115+
expression:
116+
/app\.travis-ci\.com\/(github|bitbucket|gitlab)\/[^/]+\/([^/]+)\/?.*$/,
117+
group: 2,
118+
},
119+
{
120+
expression:
121+
/app\.travis-ci\.org\/(github|bitbucket|gitlab)\/[^/]+\/([^/]+)\/?.*$/,
122+
group: 2,
123+
},
111124
];
112125

113126
for (const pattern of patterns) {
114-
const match = url.match(pattern);
127+
const match = url.match(pattern.expression);
115128
if (match) {
116-
// Adjusted to capture the right group based on the pattern.
117-
// The group index might be 2 if the pattern includes a platform prefix before the project name.
118-
const groupIndex = pattern.source.includes("(github|bitbucket|gitlab)")
119-
? 2
120-
: 1;
121-
return match[groupIndex];
129+
return match[pattern.group];
122130
}
123131
}
124132

0 commit comments

Comments
 (0)