Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
});
}

// Skip negatives for this one, it's too long
if (detectName === 'isRepo') {
continue;
}

for (const url of allUrls) {
if (!validURLs.includes(url)) {
test(`${detectName} NO ${url}`, () => {
Expand Down
46 changes: 40 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function exists(selector: string): boolean {
* ```
*/
async function waitFor(detection: () => boolean): Promise<boolean> {
// eslint-disable-next-line no-await-in-loop -- We need to wait on each frame
while (!detection() && document.readyState !== 'complete') {
// eslint-disable-next-line no-await-in-loop
await new Promise(resolve => {
Expand Down Expand Up @@ -457,11 +456,46 @@ export const isRepo = (url: URL | HTMLAnchorElement | Location = location): bool
};

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/', // Gotcha for isNotifications
'https://github.com/sindresorhus/refined-github/pull/148',
'isActionRun', // Includes isActionJobRun URLs
'isBranches',
'isCompare', // Includes isQuickPR URLs
'isDeletingFile',
'isEditingFile',
'isEditingRelease',
'isFileFinder',
'isForkingRepo',
'isIssue',
'isLabelList',
'isMilestone',
'isMilestoneList',
'isNewAction',
'isNewFile',
'isNewIssue',
'isNewRelease',
'isPR', // Includes isPRConversation, isPRFiles (→isPRCommit), isPRCommitList
'isPRConflicts',
'isProjects',
'isReleases',
'isRepoPRList',
'isRepoCommitList',
'isRepoForksList',
'isRepoGitObject', // Includes isRepoTree (→isRepoRoot→isRepoHome), isSingleFile (→isRenderedTextFile), isBlame
'isRepoIssueList',
'isRepoNetworkGraph',
'isRepoSearch',
'isRepoSettings', // Includes isRepoMainSettings
'isRepoTaxonomyIssueOrPRList',
'isRepoWiki', // Includes isNewWikiPage, isEditingWikiPage, isCompareWikiPage
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are not required and they don't have to be kept up to date, but it's good to have them as a sanity check in the future.

LLMs are good at keeping these lists up to date anyway.

'isRepositoryActions',
'isSingleCommit',
'isSingleReleaseOrTag',
'isTags',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holy cow that's a lot 😂 but better than repeating all the URLs.

Not sure if it's worth removing the exception… but having no exceptions is always better.

// Repo URLs from detections that also cover non-repo pages
'https://github.com/sindresorhus/refined-github/projects/3', // From isProject
'https://github.com/tophf/mpiv/discussions/50', // From isDiscussion
'https://github.com/withastro/roadmap/discussions/new?category=proposal', // From isNewDiscussion
'https://github.com/tophf/mpiv/discussions', // From isDiscussionList
// These URLs are repos but don't match any specific detection
'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
Expand Down
Loading