Skip to content

Commit 52d5e2a

Browse files
isPRList - Support global PR list subpaths (#245)
1 parent c1e5e3f commit 52d5e2a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

index.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,28 @@ TEST: addTests('isGist', [
183183
'https://gist.my-little-hub.com/in-fragrante',
184184
]);
185185

186-
export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => ['issues', 'pulls'].includes(url.pathname.split('/', 2)[1]!);
187-
TEST: addTests('isGlobalIssueOrPRList', [
186+
export const isGlobalIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^issues($|\/)/.test(getCleanPathname(url));
187+
TEST: addTests('isGlobalIssueList', [
188188
'https://github.com/issues',
189-
'https://github.com/issues?q=is%3Apr+is%3Aopen',
190189
'https://github.com/issues/assigned',
191190
'https://github.com/issues/mentioned',
191+
'https://github.com/issues?q=is%3Apr+is%3Aopen',
192+
'https://github.com//issues/',
193+
]);
194+
195+
export const isGlobalPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pulls($|\/)/.test(getCleanPathname(url));
196+
TEST: addTests('isGlobalPRList', [
192197
'https://github.com/pulls',
193-
'https://github.com/pulls?q=issues',
194198
'https://github.com/pulls/assigned',
195199
'https://github.com/pulls/mentioned',
196200
'https://github.com/pulls/review-requested',
201+
'https://github.com/pulls?q=issues',
202+
'https://github.com//pulls/',
197203
]);
198204

205+
export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isGlobalPRList(url) || isGlobalIssueList(url);
206+
TEST: addTests('isGlobalIssueOrPRList', combinedTestOnly);
207+
199208
export const isGlobalSearchResults = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/search' && new URLSearchParams(url.search).get('q') !== null;
200209
TEST: addTests('isGlobalSearchResults', [
201210
'https://github.com/search?q=refined-github&ref=opensearch',
@@ -318,15 +327,8 @@ TEST: addTests('isPRConflicts', [
318327
]);
319328

320329
/** Any `isIssueOrPRList` can display both issues and PRs, prefer that detection. `isPRList` only exists because this page has PR-specific filters like the "Reviews" dropdown */
321-
export const isPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/pulls' || getRepo(url)?.path === 'pulls';
322-
TEST: addTests('isPRList', [
323-
'https://github.com/pulls',
324-
'https://github.com/pulls?q=issues',
325-
'https://github.com/sindresorhus/refined-github/pulls',
326-
'https://github.com/sindresorhus/refined-github/pulls/',
327-
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr',
328-
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed',
329-
]);
330+
export const isPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoPRList(url) || isGlobalPRList(url);
331+
TEST: addTests('isPRList', combinedTestOnly);
330332

331333
export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path);
332334
TEST: addTests('isPRCommit', [
@@ -458,7 +460,7 @@ TEST: addTests('isRepo', [
458460
// Some of these are here simply as "gotchas" to other detections
459461
'https://github.com/sindresorhus/refined-github/blame/master/package.json',
460462
'https://github.com/sindresorhus/refined-github/issues/146',
461-
'https://github.com/sindresorhus/notifications/',
463+
'https://github.com/sindresorhus/notifications/', // Gotcha for isNotifications
462464
'https://github.com/sindresorhus/refined-github/pull/148',
463465
'https://github.com/sindresorhus/refined-github/milestones/new', // Gotcha for isRepoTaxonomyIssueOrPRList
464466
'https://github.com/sindresorhus/refined-github/milestones/1/edit', // Gotcha for isRepoTaxonomyIssueOrPRList
@@ -538,6 +540,8 @@ TEST: addTests('isRepoHome', [
538540
'https://github.com/sindresorhus/search',
539541
'https://github.com/sindresorhus/branches',
540542
'https://github.com/sindresorhus/refined-github?files=1',
543+
'https://github.com/pullsuser/my-library', // Gotcha for isRepoPRList
544+
'https://github.com/issuesuser/my-library', // Gotcha for isRepoIssueList
541545
]);
542546

543547
export type RepoExplorerInfo = {
@@ -791,6 +795,8 @@ TEST: addTests('isProfile', [
791795
'https://github.com/sindresorhus?tab=followers',
792796
'https://github.com/fregante?tab=following',
793797
'https://github.com/sindresorhus?tab=following',
798+
'https://github.com/pullsuser', // Gotcha for isGlobalPRList
799+
'https://github.com/issuesuser', // Gotcha for isGlobalIssueList
794800
]);
795801

796802
export const isGistProfile = (url: URL | HTMLAnchorElement | Location = location): boolean => doesLookLikeAProfile(getCleanGistPathname(url));

0 commit comments

Comments
 (0)