1- /* eslint-disable unicorn/prefer-starts-ends-with, @typescript-eslint/prefer-string-starts-ends-with */
21/* The tested var might not be a string */
32
43import select from 'select-dom' ;
@@ -11,10 +10,10 @@ const domBased = 'skip'; // To be used only to skip tests that are DOM-based rat
1110export const is404 = ( ) : boolean => document . title === 'Page not found · GitHub' ;
1211export const _is404 = domBased ; // They're specified in page-detect.ts
1312
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' ;
1514export const _is500 = domBased ; // They're specified in page-detect.ts
1615
17- export const isBlame = ( ) : boolean => / ^ b l a m e \/ / . test ( getRepoPath ( ) ! ) ;
16+ export const isBlame = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'blame/' ) ;
1817export const _isBlame = [
1918 'https://github.com/sindresorhus/refined-github/blame/master/package.json'
2019] ;
@@ -37,7 +36,7 @@ export const _isCommitList = [
3736 'https://github.com/sindresorhus/refined-github/pull/148/commits'
3837] ;
3938
40- export const isRepoCommitList = ( ) : boolean => / ^ c o m m i t s \/ / . test ( getRepoPath ( ) ! ) ;
39+ export const isRepoCommitList = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'commits/' ) ;
4140export const _isRepoCommitList = [
4241 'https://github.com/sindresorhus/refined-github/commits/master?page=2' ,
4342 'https://github.com/sindresorhus/refined-github/commits/test-branch' ,
@@ -46,7 +45,7 @@ export const _isRepoCommitList = [
4645 'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63'
4746] ;
4847
49- export const isCompare = ( ) : boolean => / ^ c o m p a r e / . test ( getRepoPath ( ) ! ) ;
48+ export const isCompare = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'compare' ) ;
5049export const _isCompare = [
5150 'https://github.com/sindresorhus/refined-github/compare' ,
5251 'https://github.com/sindresorhus/refined-github/compare/' ,
@@ -126,12 +125,12 @@ export const _isMilestoneList = [
126125 'https://github.com/sindresorhus/refined-github/milestones'
127126] ;
128127
129- export const isNewIssue = ( ) : boolean => / ^ i s s u e s \/ n e w / . test ( getRepoPath ( ) ! ) ;
128+ export const isNewIssue = ( ) : boolean => getRepoPath ( ) === 'issues/new' ;
130129export const _isNewIssue = [
131130 'https://github.com/sindresorhus/refined-github/issues/new'
132131] ;
133132
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' ;
135134export const _isNewRelease = [
136135 'https://github.com/sindresorhus/refined-github/releases/new'
137136] ;
@@ -222,19 +221,15 @@ export const _isQuickPR = [
222221 'https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1'
223222] ;
224223
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 ( ) ! ) ;
230225export const _isReleasesOrTags = [
231226 'https://github.com/sindresorhus/refined-github/releases' ,
232227 'https://github.com/sindresorhus/refined-github/tags' ,
233228 'https://github.com/sindresorhus/refined-github/releases/tag/v1.0.0-beta.4' ,
234229 'https://github.com/sindresorhus/refined-github/releases/tag/0.2.1'
235230] ;
236231
237- export const isEditingFile = ( ) : boolean => / ^ e d i t / . test ( getRepoPath ( ) ! ) ;
232+ export const isEditingFile = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'edit' ) ;
238233export const _isEditingFile = [
239234 'https://github.com/sindresorhus/refined-github/edit/master/readme.md' ,
240235 'https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts'
@@ -247,49 +242,48 @@ export const isRepo = (): boolean => /^[^/]+\/[^/]+/.test(getCleanPathname()) &&
247242 ! isGist ( ) &&
248243 ! isRepoSearch ( ) ;
249244export const _isRepo = [
245+ // Some of these are here simply as "gotchas" to other detections
250246 'https://github.com/sindresorhus/refined-github/blame/master/package.json' ,
251247 'https://github.com/sindresorhus/refined-github/issues/146' ,
252248 '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
254254] ;
255255export const _isRepoSkipNegatives = true ;
256256
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+
257263export const isRepoDiscussionList = ( ) : boolean =>
258264 isRepoPRList ( ) ||
259265 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 ;
274268
275- export const isRepoPRList = ( ) : boolean => ( getRepoPath ( ) ?? '' ) . startsWith ( 'pulls' ) ;
269+ export const isRepoPRList = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'pulls' ) ;
276270export const _isRepoPRList = [
277271 'https://github.com/sindresorhus/refined-github/pulls' ,
278272 'https://github.com/sindresorhus/refined-github/pulls/' ,
279- 'https://github.com/sindresorhus/refined-github/pulls/fregante' ,
280273 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr' ,
281274 'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed'
282275] ;
283276
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 ( ) ! ) ;
289281export const _isRepoIssueList = [
290282 'http://github.com/sindresorhus/ava/issues' ,
291283 'https://github.com/sindresorhus/refined-github/issues' ,
292284 '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' ,
293287 'https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc'
294288] ;
295289
@@ -311,20 +305,22 @@ export const _isRepoRoot = [
311305 'https://github.com/sindresorhus/branches'
312306] ;
313307
308+ // This can't use `getRepoPath` to avoid infinite recursion.
309+ // `getRepoPath` depends on `isRepo` and `isRepo` depends on `isRepoSearch`
314310export const isRepoSearch = ( ) : boolean => location . pathname . slice ( 1 ) . split ( '/' ) [ 2 ] === 'search' ;
315311export const _isRepoSearch = [
316312 'https://github.com/sindresorhus/refined-github/search?q=diff' ,
317313 'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues' ,
318314 'https://github.com/sindresorhus/refined-github/search'
319315] ;
320316
321- export const isRepoSettings = ( ) : boolean => / ^ s e t t i n g s / . test ( getRepoPath ( ) ! ) ;
317+ export const isRepoSettings = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'settings' ) ;
322318export const _isRepoSettings = [
323319 'https://github.com/sindresorhus/refined-github/settings' ,
324320 'https://github.com/sindresorhus/refined-github/settings/branches'
325321] ;
326322
327- export const isRepoTree = ( ) : boolean => isRepoRoot ( ) || / ^ t r e e \/ / . test ( getRepoPath ( ) ! ) ;
323+ export const isRepoTree = ( ) : boolean => isRepoRoot ( ) || String ( getRepoPath ( ) ) . startsWith ( 'tree/' ) ;
328324export const _isRepoTree = [
329325 'https://github.com/sindresorhus/refined-github/tree/master/distribution' ,
330326 'https://github.com/sindresorhus/refined-github/tree/0.13.0/distribution' ,
@@ -340,14 +336,14 @@ export const _isSingleCommit = [
340336 'https://github.com/sindresorhus/refined-github/commit/5b614'
341337] ;
342338
343- export const isSingleFile = ( ) : boolean => / ^ b l o b \/ / . test ( getRepoPath ( ) ! ) ;
339+ export const isSingleFile = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'blob/' ) ;
344340export const _isSingleFile = [
345341 'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes' ,
346342 'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css' ,
347343 'https://github.com/sindresorhus/refined-github/blob/master/edit.txt'
348344] ;
349345
350- export const isFileFinder = ( ) : boolean => / ^ f i n d \/ / . test ( getRepoPath ( ) ! ) ;
346+ export const isFileFinder = ( ) : boolean => String ( getRepoPath ( ) ) . startsWith ( 'find/' ) ;
351347export const _isFileFinder = [
352348 'https://github.com/sindresorhus/refined-github/find/master'
353349] ;
0 commit comments