1
- /* eslint-disable unicorn/prefer-starts-ends-with, @typescript-eslint/prefer-string-starts-ends-with */
2
1
/* The tested var might not be a string */
3
2
4
3
import select from 'select-dom' ;
@@ -11,10 +10,10 @@ const domBased = 'skip'; // To be used only to skip tests that are DOM-based rat
11
10
export const is404 = ( ) : boolean => document . title === 'Page not found · GitHub' ;
12
11
export const _is404 = domBased ; // They're specified in page-detect.ts
13
12
14
- export const is500 = ( ) : boolean => document . title === 'Server Error · GitHub' || document . title === 'Unicorn! · GitHub' ;
13
+ export const is500 = ( ) : boolean => document . title === 'Server Error · GitHub' || document . title === 'Unicorn! · GitHub' || document . title === '504 Gateway Time-out' ;
15
14
export const _is500 = domBased ; // They're specified in page-detect.ts
16
15
17
- export const isBlame = ( ) : boolean => / ^ b l a m e \/ / . test ( getRepoPath ( ) ! ) ;
16
+ export const isBlame = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'blame/' ) ;
18
17
export const _isBlame = [
19
18
'https://github.com/sindresorhus/refined-github/blame/master/package.json'
20
19
] ;
@@ -37,7 +36,7 @@ export const _isCommitList = [
37
36
'https://github.com/sindresorhus/refined-github/pull/148/commits'
38
37
] ;
39
38
40
- export const isRepoCommitList = ( ) : boolean => / ^ c o m m i t s \/ / . test ( getRepoPath ( ) ! ) ;
39
+ export const isRepoCommitList = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'commits/' ) ;
41
40
export const _isRepoCommitList = [
42
41
'https://github.com/sindresorhus/refined-github/commits/master?page=2' ,
43
42
'https://github.com/sindresorhus/refined-github/commits/test-branch' ,
@@ -46,7 +45,7 @@ export const _isRepoCommitList = [
46
45
'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63'
47
46
] ;
48
47
49
- export const isCompare = ( ) : boolean => / ^ c o m p a r e / . test ( getRepoPath ( ) ! ) ;
48
+ export const isCompare = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'compare' ) ;
50
49
export const _isCompare = [
51
50
'https://github.com/sindresorhus/refined-github/compare' ,
52
51
'https://github.com/sindresorhus/refined-github/compare/' ,
@@ -126,12 +125,12 @@ export const _isMilestoneList = [
126
125
'https://github.com/sindresorhus/refined-github/milestones'
127
126
] ;
128
127
129
- export const isNewIssue = ( ) : boolean => / ^ i s s u e s \/ n e w / . test ( getRepoPath ( ) ! ) ;
128
+ export const isNewIssue = ( ) : boolean => getRepoPath ( ) === 'issues/new' ;
130
129
export const _isNewIssue = [
131
130
'https://github.com/sindresorhus/refined-github/issues/new'
132
131
] ;
133
132
134
- export const isNewRelease = ( ) : boolean => / ^ r e l e a s e s \/ n e w / . test ( getRepoPath ( ) ! ) ;
133
+ export const isNewRelease = ( ) : boolean => getRepoPath ( ) === 'releases/new' ;
135
134
export const _isNewRelease = [
136
135
'https://github.com/sindresorhus/refined-github/releases/new'
137
136
] ;
@@ -222,19 +221,15 @@ export const _isQuickPR = [
222
221
'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1'
223
222
] ;
224
223
225
- export const isReleasesOrTags = ( ) : boolean => {
226
- const parts = ( getRepoPath ( ) ?? '' ) . split ( '/' ) ;
227
- return / ^ ( r e l e a s e s | t a g s ) $ / . test ( parts [ 0 ] ) && parts [ 1 ] !== 'new' ;
228
- } ;
229
-
224
+ export const isReleasesOrTags = ( ) : boolean => / ^ t a g s $ | ^ r e l e a s e s ( $ | \/ t a g ) / . test ( getRepoPath ( ) ! ) ;
230
225
export const _isReleasesOrTags = [
231
226
'https://github.com/sindresorhus/refined-github/releases' ,
232
227
'https://github.com/sindresorhus/refined-github/tags' ,
233
228
'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4' ,
234
229
'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
235
230
] ;
236
231
237
- export const isEditingFile = ( ) : boolean => / ^ e d i t / . test ( getRepoPath ( ) ! ) ;
232
+ export const isEditingFile = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'edit' ) ;
238
233
export const _isEditingFile = [
239
234
'https://github.com/sindresorhus/refined-github/edit/master/readme.md' ,
240
235
'https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts'
@@ -247,49 +242,48 @@ export const isRepo = (): boolean => /^[^/]+\/[^/]+/.test(getCleanPathname()) &&
247
242
! isGist ( ) &&
248
243
! isRepoSearch ( ) ;
249
244
export const _isRepo = [
245
+ // Some of these are here simply as "gotchas" to other detections
250
246
'https://github.com/sindresorhus/refined-github/blame/master/package.json' ,
251
247
'https://github.com/sindresorhus/refined-github/issues/146' ,
252
248
'https://github.com/sindresorhus/notifications/' ,
253
- 'https://github.com/sindresorhus/refined-github/pull/148'
249
+ 'https://github.com/sindresorhus/refined-github/pull/148' ,
250
+ 'https://github.com/sindresorhus/refined-github/milestones/new' , // Gotcha for isRepoTaxonomyDiscussionList
251
+ 'https://github.com/sindresorhus/refined-github/milestones/1/edit' , // Gotcha for isRepoTaxonomyDiscussionList
252
+ 'https://github.com/sindresorhus/refined-github/issues/new/choose' , // Gotcha for isRepoIssueList
253
+ 'https://github.com/sindresorhus/refined-github/issues/templates/edit' // Gotcha for isRepoIssueList
254
254
] ;
255
255
export const _isRepoSkipNegatives = true ;
256
256
257
+ export const isRepoTaxonomyDiscussionList = ( ) : boolean => / ^ l a b e l s \/ .+ | ^ m i l e s t o n e s \/ \d + (? ! \/ e d i t ) / . test ( getRepoPath ( ) ! ) ;
258
+ export const _isRepoTaxonomyDiscussionList = [
259
+ 'https://github.com/sindresorhus/refined-github/labels/Priority%3A%20critical' ,
260
+ 'https://github.com/sindresorhus/refined-github/milestones/1'
261
+ ] ;
262
+
257
263
export const isRepoDiscussionList = ( ) : boolean =>
258
264
isRepoPRList ( ) ||
259
265
isRepoIssueList ( ) ||
260
- / ^ ( l a b e l s | m i l e s t o n e s ) \/ .+ / . test ( getRepoPath ( ) ! ) ;
261
- export const _isRepoDiscussionList = [
262
- 'http://github.com/sindresorhus/ava/issues' ,
263
- 'https://github.com/sindresorhus/refined-github/pulls' ,
264
- 'https://github.com/sindresorhus/refined-github/pulls/' ,
265
- 'https://github.com/sindresorhus/refined-github/pulls/fregante' ,
266
- 'https://github.com/sindresorhus/refined-github/issues/fregante' ,
267
- 'https://github.com/sindresorhus/refined-github/labels/Priority%3A%20critical' ,
268
- 'https://github.com/sindresorhus/refined-github/milestones/1.0' ,
269
- 'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc' ,
270
- 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
271
- 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed' ,
272
- 'https://github.com/sindresorhus/refined-github/issues'
273
- ] ;
266
+ isRepoTaxonomyDiscussionList ( ) ;
267
+ export const _isRepoDiscussionList = skip ;
274
268
275
- export const isRepoPRList = ( ) : boolean => ( getRepoPath ( ) ?? '' ) . startsWith ( 'pulls' ) ;
269
+ export const isRepoPRList = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'pulls' ) ;
276
270
export const _isRepoPRList = [
277
271
'https://github.com/sindresorhus/refined-github/pulls' ,
278
272
'https://github.com/sindresorhus/refined-github/pulls/' ,
279
- 'https://github.com/sindresorhus/refined-github/pulls/fregante' ,
280
273
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
281
274
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed'
282
275
] ;
283
276
284
- export const isRepoIssueList = ( ) : boolean => {
285
- const parts = ( getRepoPath ( ) ?? '' ) . split ( '/' ) ;
286
- return parts [ 0 ] === 'issues' && parts [ 1 ] !== 'new' && ! / \d / . test ( parts [ 1 ] ) ; // `issues/fregante` is a list but `issues/1` isn't
287
- } ;
288
-
277
+ // `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t
278
+ export const isRepoIssueList = ( ) : boolean =>
279
+ String ( getRepoPath ( ) ) . startsWith ( 'issues' ) &&
280
+ ! / ^ i s s u e s \/ ( \d + | n e w | t e m p l a t e s ) ( $ | \/ ) / . test ( getRepoPath ( ) ! ) ;
289
281
export const _isRepoIssueList = [
290
282
'http://github.com/sindresorhus/ava/issues' ,
291
283
'https://github.com/sindresorhus/refined-github/issues' ,
292
284
'https://github.com/sindresorhus/refined-github/issues/fregante' ,
285
+ 'https://github.com/sindresorhus/refined-github/issues/newton' ,
286
+ 'https://github.com/sindresorhus/refined-github/issues/wptemplates' ,
293
287
'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc'
294
288
] ;
295
289
@@ -311,20 +305,22 @@ export const _isRepoRoot = [
311
305
'https://github.com/sindresorhus/branches'
312
306
] ;
313
307
308
+ // This can't use `getRepoPath` to avoid infinite recursion.
309
+ // `getRepoPath` depends on `isRepo` and `isRepo` depends on `isRepoSearch`
314
310
export const isRepoSearch = ( ) : boolean => location . pathname . slice ( 1 ) . split ( '/' ) [ 2 ] === 'search' ;
315
311
export const _isRepoSearch = [
316
312
'https://github.com/sindresorhus/refined-github/search?q=diff' ,
317
313
'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues' ,
318
314
'https://github.com/sindresorhus/refined-github/search'
319
315
] ;
320
316
321
- export const isRepoSettings = ( ) : boolean => / ^ s e t t i n g s / . test ( getRepoPath ( ) ! ) ;
317
+ export const isRepoSettings = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'settings' ) ;
322
318
export const _isRepoSettings = [
323
319
'https://github.com/sindresorhus/refined-github/settings' ,
324
320
'https://github.com/sindresorhus/refined-github/settings/branches'
325
321
] ;
326
322
327
- export const isRepoTree = ( ) : boolean => isRepoRoot ( ) || / ^ t r e e \/ / . test ( getRepoPath ( ) ! ) ;
323
+ export const isRepoTree = ( ) : boolean => isRepoRoot ( ) || String ( getRepoPath ( ) ) . startsWith ( 'tree/' ) ;
328
324
export const _isRepoTree = [
329
325
'https://github.com/sindresorhus/refined-github/tree/master/distribution' ,
330
326
'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution' ,
@@ -340,14 +336,14 @@ export const _isSingleCommit = [
340
336
'https://github.com/sindresorhus/refined-github/commit/5b614'
341
337
] ;
342
338
343
- export const isSingleFile = ( ) : boolean => / ^ b l o b \/ / . test ( getRepoPath ( ) ! ) ;
339
+ export const isSingleFile = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'blob/' ) ;
344
340
export const _isSingleFile = [
345
341
'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes' ,
346
342
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css' ,
347
343
'https://github.com/sindresorhus/refined-github/blob/master/edit.txt'
348
344
] ;
349
345
350
- export const isFileFinder = ( ) : boolean => / ^ f i n d \/ / . test ( getRepoPath ( ) ! ) ;
346
+ export const isFileFinder = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'find/' ) ;
351
347
export const _isFileFinder = [
352
348
'https://github.com/sindresorhus/refined-github/find/master'
353
349
] ;
0 commit comments