Skip to content
44 changes: 26 additions & 18 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,28 @@ TEST: addTests('isGist', [
'https://gist.my-little-hub.com/in-fragrante',
]);

export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => ['issues', 'pulls'].includes(url.pathname.split('/', 2)[1]!);
TEST: addTests('isGlobalIssueOrPRList', [
export const isGlobalIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^issues($|\/)/.test(getCleanPathname(url));
TEST: addTests('isGlobalIssueList', [
'https://github.com/issues',
'https://github.com/issues?q=is%3Apr+is%3Aopen',
'https://github.com/issues/assigned',
'https://github.com/issues/mentioned',
'https://github.com/issues?q=is%3Apr+is%3Aopen',
'https://github.com//issues/',
]);

export const isGlobalPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pulls($|\/)/.test(getCleanPathname(url));
TEST: addTests('isGlobalPRList', [
'https://github.com/pulls',
'https://github.com/pulls?q=issues',
'https://github.com/pulls/assigned',
'https://github.com/pulls/mentioned',
'https://github.com/pulls/review-requested',
'https://github.com/pulls?q=issues',
'https://github.com//pulls/',
]);

export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isGlobalIssueList(url) || isGlobalPRList(url);
TEST: addTests('isGlobalIssueOrPRList', combinedTestOnly);

export const isGlobalSearchResults = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/search' && new URLSearchParams(url.search).get('q') !== null;
TEST: addTests('isGlobalSearchResults', [
'https://github.com/search?q=refined-github&ref=opensearch',
Expand All @@ -206,10 +215,10 @@ TEST: addTests('isIssue', [
'https://github.com/sindresorhus/refined-github/issues/146',
]);

export const isIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean =>
isGlobalIssueOrPRList(url)
|| isRepoIssueOrPRList(url)
|| isMilestone(url);
export const isIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoIssueList(url) || isGlobalIssueList(url) || isMilestone(url);
TEST: addTests('isIssueList', combinedTestOnly);

export const isIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isIssueList(url) || isPRList(url);
TEST: addTests('isIssueOrPRList', combinedTestOnly);

export const isConversation = (url: URL | HTMLAnchorElement | Location = location): boolean => isIssue(url) || isPRConversation(url);
Expand Down Expand Up @@ -318,15 +327,8 @@ TEST: addTests('isPRConflicts', [
]);

/** 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 */
export const isPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/pulls' || getRepo(url)?.path === 'pulls';
TEST: addTests('isPRList', [
'https://github.com/pulls',
'https://github.com/pulls?q=issues',
'https://github.com/sindresorhus/refined-github/pulls',
'https://github.com/sindresorhus/refined-github/pulls/',
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr',
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed',
]);
export const isPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isGlobalPRList(url) || isRepoPRList(url);
TEST: addTests('isPRList', combinedTestOnly);

export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path);
TEST: addTests('isPRCommit', [
Expand Down Expand Up @@ -458,12 +460,14 @@ TEST: addTests('isRepo', [
// Some of these are here simply as "gotchas" to other detections
'https://github.com/sindresorhus/refined-github/blame/master/package.json',
'https://github.com/sindresorhus/refined-github/issues/146',
'https://github.com/sindresorhus/notifications/',
'https://github.com/sindresorhus/notifications/', // Gotcha for isNotifications
'https://github.com/sindresorhus/refined-github/pull/148',
'https://github.com/sindresorhus/refined-github/milestones/new', // Gotcha for isRepoTaxonomyIssueOrPRList
'https://github.com/sindresorhus/refined-github/milestones/1/edit', // Gotcha for isRepoTaxonomyIssueOrPRList
'https://github.com/sindresorhus/refined-github/issues/new/choose', // Gotcha for isRepoIssueList
'https://github.com/sindresorhus/refined-github/issues/templates/edit', // Gotcha for isRepoIssueList
'https://github.com/pullsuser/my-library', // Gotcha for isRepoPRList
'https://github.com/issuesuser/my-library', // Gotcha for isRepoIssueList
]);

export const hasRepoHeader = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepo(url) && !isRepoSearch(url);
Expand Down Expand Up @@ -538,6 +542,8 @@ TEST: addTests('isRepoHome', [
'https://github.com/sindresorhus/search',
'https://github.com/sindresorhus/branches',
'https://github.com/sindresorhus/refined-github?files=1',
'https://github.com/pullsuser/my-library', // Gotcha for isRepoPRList
'https://github.com/issuesuser/my-library', // Gotcha for isRepoIssueList
]);

export type RepoExplorerInfo = {
Expand Down Expand Up @@ -791,6 +797,8 @@ TEST: addTests('isProfile', [
'https://github.com/sindresorhus?tab=followers',
'https://github.com/fregante?tab=following',
'https://github.com/sindresorhus?tab=following',
'https://github.com/pullsuser', // Gotcha for isGlobalPRList
'https://github.com/issuesuser', // Gotcha for isGlobalIssueList
]);

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