From ddaaba19bfe02eb0dbf6a7019d407371c2fbd978 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sat, 23 Jul 2022 16:42:44 +0700 Subject: [PATCH 1/3] Include Repo Search pages in `isRepo`; add `hasRepoHeader` --- index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 0c3956ac..8d806009 100644 --- a/index.ts +++ b/index.ts @@ -331,7 +331,6 @@ export const isRepo = (url: URL | HTMLAnchorElement | Location = location): bool && !reservedNames.includes(url.pathname.split('/', 2)[1]!) && !isDashboard(url) && !isGist(url) - && !isRepoSearch(url) && !isNewRepoTemplate(url); addTests('isRepo', [ // Some of these are here simply as "gotchas" to other detections @@ -345,6 +344,9 @@ addTests('isRepo', [ 'https://github.com/sindresorhus/refined-github/issues/templates/edit', // Gotcha for isRepoIssueList ]); +export const hasRepoHeader = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepo(url) && !isRepoSearch(url); +addTests('hasRepoHeader', combinedTestOnly); + // On empty repos, there's only isRepoHome; this element is found in `` export const isEmptyRepoRoot = (): boolean => isRepoHome() && !exists('link[rel="canonical"]'); From b47cf047cfd51df93aefcf3567817b05add29bf4 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sun, 24 Jul 2022 18:55:59 +0700 Subject: [PATCH 2/3] Finally drop awkward code path in isRepoSearch itself --- index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 8d806009..ab4fbb13 100644 --- a/index.ts +++ b/index.ts @@ -437,9 +437,7 @@ addTests('isRepoRoot', [ 'https://github.com/sindresorhus/refined-github/tree/master?files=1', ]); -// This can't use `getRepositoryInfo().path` to avoid infinite recursion: -// `getRepositoryInfo` depends on `isRepo` and `isRepo` depends on `isRepoSearch` -export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname.split('/')[3] === 'search'; +export const isRepoSearch = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'search';; addTests('isRepoSearch', [ 'https://github.com/sindresorhus/refined-github/search?q=diff', 'https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues', From 28c6d6c7ba7be43bbe140e52f20627dbc31bbe98 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sun, 24 Jul 2022 18:59:43 +0700 Subject: [PATCH 3/3] Unrelated: move some comments to JSDoct --- index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index ab4fbb13..efe98037 100644 --- a/index.ts +++ b/index.ts @@ -616,7 +616,8 @@ export const hasRichTextEditor = (url: URL | HTMLAnchorElement | Location = loca || isDiscussion(url); addTests('hasCode', combinedTestOnly); -export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boolean => // Static code, not the editor +/** Static code, not the code editor */ +export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boolean => hasComments(url) || isRepoTree(url) // Readme files || isRepoSearch(url) @@ -628,7 +629,8 @@ export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boo || isBlame(url); addTests('hasFiles', combinedTestOnly); -export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => // Has a list of files +/** Has a list of files */ +export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => isCommit(url) || isCompare(url) || isPRFiles(url);