File tree Expand file tree Collapse file tree 5 files changed +29
-19
lines changed
Expand file tree Collapse file tree 5 files changed +29
-19
lines changed Original file line number Diff line number Diff line change 1616
1717 "content_scripts" : [
1818 {
19- "matches" : [" *://github.com/*/*/blob/*" ],
20- "js" : [" js/vendor.js" , " js/githubFile.js" ]
21- },
22- {
23- "matches" : [" *://github.com/*/*/pull/*/files*" ],
24- "js" : [" js/vendor.js" , " js/githubPR.js" ]
19+ "matches" : [" *://github.com/*" ],
20+ "js" : [" js/vendor.js" , " js/githubFile.js" , " js/githubPR.js" ]
2521 }
2622 ],
2723
Original file line number Diff line number Diff line change 1616
1717 "content_scripts" : [
1818 {
19- "matches" : [" *://github.com/*/*/blob/*" ],
20- "js" : [" js/vendor.js" , " js/githubFile.js" ]
21- },
22- {
23- "matches" : [" *://github.com/*/*/pull/*/files*" ],
24- "js" : [" js/vendor.js" , " js/githubPR.js" ]
19+ "matches" : [" *://github.com/*" ],
20+ "js" : [" js/vendor.js" , " js/githubFile.js" , " js/githubPR.js" ]
2521 }
2622 ],
2723
Original file line number Diff line number Diff line change 1+ // Note that we're guaranteed to be on a github page due to manifest.json,
2+ // so these checks don't need to include that.
3+ const prUrlRegex = / \/ [ ^ \/ ] + \/ [ ^ \/ ] + \/ p u l l \/ \d + \/ f i l e s .* /
4+ const fileUrlRegex = / \/ [ ^ \/ ] + \/ [ ^ \/ ] + \/ b l o b \/ [ ^ \/ ] + \/ .* /
5+
6+ export function isFileUrl ( url : string ) : boolean {
7+ return fileUrlRegex . test ( url ) ;
8+ }
9+
10+ export function isPrUrl ( url : string ) : boolean {
11+ return prUrlRegex . test ( url ) ;
12+ }
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import {
1212 FileCoverageReport ,
1313 FileCoverageReportResponse ,
1414 FileMetadata ,
15- MessageType ,
1615} from "src/types" ;
1716import {
1817 componentsStorageKey ,
@@ -34,6 +33,7 @@ import {
3433 getBranchReport ,
3534} from "../common/fetchers" ;
3635import { print } from "src/utils" ;
36+ import { isFileUrl } from "../common/utils" ;
3737
3838const globals : {
3939 coverageReport ?: FileCoverageReport ;
@@ -60,15 +60,14 @@ function init(): Promise<void> {
6060}
6161
6262async function main ( ) : Promise < void > {
63- let metadata : FileMetadata ;
64-
65- try {
66- metadata = await getMetadata ( document . URL ) ;
67- } catch ( e ) {
63+ if ( ! isFileUrl ( document . URL ) ) {
6864 print ( "file not detected at current URL" ) ;
6965 return ;
7066 }
7167
68+ let metadata : FileMetadata ;
69+ metadata = await getMetadata ( document . URL ) ;
70+
7271 globals . coverageButton = createCoverageButton ( ) ;
7372
7473 process ( metadata ) . catch ( ( e ) => {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import _ from "lodash";
44
55import "src/basscss.css" ;
66import { displayChange } from "src/utils" ;
7- import { CoverageStatus , MessageType , PullCoverageReport } from "src/types" ;
7+ import { CoverageStatus , PullCoverageReport } from "src/types" ;
88import {
99 animateAndAnnotateLines ,
1010 clearAnimation ,
@@ -14,6 +14,7 @@ import { lineSelector } from "./constants";
1414import { colors } from "../common/constants" ;
1515import { print } from "src/utils" ;
1616import { getPRReport } from "../common/fetchers" ;
17+ import { isPrUrl } from "../common/utils" ;
1718
1819const globals : {
1920 coverageReport ?: PullCoverageReport ;
@@ -26,7 +27,13 @@ async function main() {
2627}
2728
2829async function execute ( ) {
30+ if ( ! isPrUrl ( document . URL ) ) {
31+ print ( "PR not detected at current URL" ) ;
32+ return ;
33+ }
34+
2935 const urlMetadata = getMetadataFromURL ( ) ;
36+
3037 if ( ! urlMetadata ) {
3138 print ( "PR not detected at current URL" ) ;
3239 return ;
You can’t perform that action at this time.
0 commit comments