diff --git a/index.ts b/index.ts index 8f24f21..81239f1 100644 --- a/index.ts +++ b/index.ts @@ -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', @@ -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', [ @@ -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 @@ -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 = { @@ -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));