Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 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 => isGlobalPRList(url) || isGlobalIssueList(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 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 => isRepoPRList(url) || isGlobalPRList(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,7 +460,7 @@ 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
Expand Down Expand Up @@ -538,6 +540,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 +795,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