Skip to content

Commit 2a2bc34

Browse files
Merge branch 'main' into decode
2 parents ce9ebb9 + 1891ab3 commit 2a2bc34

4 files changed

Lines changed: 66 additions & 31 deletions

File tree

‎index.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
5454
});
5555
}
5656

57-
// Skip negatives for this one, it's too long
58-
if (detectName === 'isRepo') {
59-
continue;
60-
}
61-
6257
for (const url of allUrls) {
6358
if (!validURLs.includes(url)) {
6459
test(`${detectName} NO ${url}`, () => {

‎index.ts‎

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function exists(selector: string): boolean {
3838
* ```
3939
*/
4040
async function waitFor(detection: () => boolean): Promise<boolean> {
41-
// eslint-disable-next-line no-await-in-loop -- We need to wait on each frame
4241
while (!detection() && document.readyState !== 'complete') {
4342
// eslint-disable-next-line no-await-in-loop
4443
await new Promise(resolve => {
@@ -183,19 +182,28 @@ TEST: addTests('isGist', [
183182
'https://gist.my-little-hub.com/in-fragrante',
184183
]);
185184

186-
export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => ['issues', 'pulls'].includes(url.pathname.split('/', 2)[1]!);
187-
TEST: addTests('isGlobalIssueOrPRList', [
185+
export const isGlobalIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^issues($|\/)/.test(getCleanPathname(url));
186+
TEST: addTests('isGlobalIssueList', [
188187
'https://github.com/issues',
189-
'https://github.com/issues?q=is%3Apr+is%3Aopen',
190188
'https://github.com/issues/assigned',
191189
'https://github.com/issues/mentioned',
190+
'https://github.com/issues?q=is%3Apr+is%3Aopen',
191+
'https://github.com//issues/',
192+
]);
193+
194+
export const isGlobalPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pulls($|\/)/.test(getCleanPathname(url));
195+
TEST: addTests('isGlobalPRList', [
192196
'https://github.com/pulls',
193-
'https://github.com/pulls?q=issues',
194197
'https://github.com/pulls/assigned',
195198
'https://github.com/pulls/mentioned',
196199
'https://github.com/pulls/review-requested',
200+
'https://github.com/pulls?q=issues',
201+
'https://github.com//pulls/',
197202
]);
198203

204+
export const isGlobalIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isGlobalPRList(url) || isGlobalIssueList(url);
205+
TEST: addTests('isGlobalIssueOrPRList', combinedTestOnly);
206+
199207
export const isGlobalSearchResults = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/search' && new URLSearchParams(url.search).get('q') !== null;
200208
TEST: addTests('isGlobalSearchResults', [
201209
'https://github.com/search?q=refined-github&ref=opensearch',
@@ -206,10 +214,10 @@ TEST: addTests('isIssue', [
206214
'https://github.com/sindresorhus/refined-github/issues/146',
207215
]);
208216

209-
export const isIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean =>
210-
isGlobalIssueOrPRList(url)
211-
|| isRepoIssueOrPRList(url)
212-
|| isMilestone(url);
217+
export const isIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoIssueList(url) || isGlobalIssueList(url) || isMilestone(url);
218+
TEST: addTests('isIssueList', combinedTestOnly);
219+
220+
export const isIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isIssueList(url) || isPRList(url);
213221
TEST: addTests('isIssueOrPRList', combinedTestOnly);
214222

215223
export const isConversation = (url: URL | HTMLAnchorElement | Location = location): boolean => isIssue(url) || isPRConversation(url);
@@ -318,15 +326,8 @@ TEST: addTests('isPRConflicts', [
318326
]);
319327

320328
/** 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-
]);
329+
export const isPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoPRList(url) || isGlobalPRList(url);
330+
TEST: addTests('isPRList', combinedTestOnly);
330331

331332
export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path);
332333
TEST: addTests('isPRCommit', [
@@ -455,11 +456,46 @@ export const isRepo = (url: URL | HTMLAnchorElement | Location = location): bool
455456
};
456457

457458
TEST: addTests('isRepo', [
458-
// Some of these are here simply as "gotchas" to other detections
459-
'https://github.com/sindresorhus/refined-github/blame/master/package.json',
460-
'https://github.com/sindresorhus/refined-github/issues/146',
461-
'https://github.com/sindresorhus/notifications/',
462-
'https://github.com/sindresorhus/refined-github/pull/148',
459+
'isActionRun', // Includes isActionJobRun URLs
460+
'isBranches',
461+
'isCompare', // Includes isQuickPR URLs
462+
'isDeletingFile',
463+
'isEditingFile',
464+
'isEditingRelease',
465+
'isFileFinder',
466+
'isForkingRepo',
467+
'isIssue',
468+
'isLabelList',
469+
'isMilestone',
470+
'isMilestoneList',
471+
'isNewAction',
472+
'isNewFile',
473+
'isNewIssue',
474+
'isNewRelease',
475+
'isPR', // Includes isPRConversation, isPRFiles (→isPRCommit), isPRCommitList
476+
'isPRConflicts',
477+
'isProjects',
478+
'isReleases',
479+
'isRepoPRList',
480+
'isRepoCommitList',
481+
'isRepoForksList',
482+
'isRepoGitObject', // Includes isRepoTree (→isRepoRoot→isRepoHome), isSingleFile (→isRenderedTextFile), isBlame
483+
'isRepoIssueList',
484+
'isRepoNetworkGraph',
485+
'isRepoSearch',
486+
'isRepoSettings', // Includes isRepoMainSettings
487+
'isRepoTaxonomyIssueOrPRList',
488+
'isRepoWiki', // Includes isNewWikiPage, isEditingWikiPage, isCompareWikiPage
489+
'isRepositoryActions',
490+
'isSingleCommit',
491+
'isSingleReleaseOrTag',
492+
'isTags',
493+
// Repo URLs from detections that also cover non-repo pages
494+
'https://github.com/sindresorhus/refined-github/projects/3', // From isProject
495+
'https://github.com/tophf/mpiv/discussions/50', // From isDiscussion
496+
'https://github.com/withastro/roadmap/discussions/new?category=proposal', // From isNewDiscussion
497+
'https://github.com/tophf/mpiv/discussions', // From isDiscussionList
498+
// These URLs are repos but don't match any specific detection
463499
'https://github.com/sindresorhus/refined-github/milestones/new', // Gotcha for isRepoTaxonomyIssueOrPRList
464500
'https://github.com/sindresorhus/refined-github/milestones/1/edit', // Gotcha for isRepoTaxonomyIssueOrPRList
465501
'https://github.com/sindresorhus/refined-github/issues/new/choose', // Gotcha for isRepoIssueList
@@ -538,6 +574,8 @@ TEST: addTests('isRepoHome', [
538574
'https://github.com/sindresorhus/search',
539575
'https://github.com/sindresorhus/branches',
540576
'https://github.com/sindresorhus/refined-github?files=1',
577+
'https://github.com/pullsuser/my-library',
578+
'https://github.com/issuesuser/my-library',
541579
]);
542580

543581
export type RepoExplorerInfo = {
@@ -791,6 +829,8 @@ TEST: addTests('isProfile', [
791829
'https://github.com/sindresorhus?tab=followers',
792830
'https://github.com/fregante?tab=following',
793831
'https://github.com/sindresorhus?tab=following',
832+
'https://github.com/pullsuser', // Gotcha for isGlobalPRList
833+
'https://github.com/issuesuser', // Gotcha for isGlobalIssueList
794834
]);
795835

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

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-url-detection",
3-
"version": "11.2.0",
3+
"version": "11.2.1",
44
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
55
"keywords": [
66
"github",

0 commit comments

Comments
 (0)