From 5ba60364d481d2752b85a06ff7341f88e30c8cc2 Mon Sep 17 00:00:00 2001 From: Federico Date: Mon, 31 Mar 2025 14:07:22 +0800 Subject: [PATCH] Add `isRepoGitObject` --- index.test.ts | 6 +++--- index.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/index.test.ts b/index.test.ts index 65325c34..652992a1 100644 --- a/index.test.ts +++ b/index.test.ts @@ -24,7 +24,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) { test(detectName + ' has tests', () => { assert.ok( Array.isArray(validURLs), - `The function \`${detectName}\` doesn’t have any tests. Set them via \`collect.set()\``, + `The function \`${detectName}\` doesn’t have any tests. Set them via \`addTests()\``, ); }); @@ -41,7 +41,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) { ${url.replace('https://github.com', '')} • Yes? The \`${detectName}\` detection is wrong and should be fixed. - • No? Remove it from its \`collect.set()\` array. + • No? Remove it from its \`addTests()\` array. `), ); }); @@ -62,7 +62,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) { Is this URL \`${detectName}\`? ${url.replace('https://github.com', '')} - • Yes? Add it to the \`collect.set()\` array. + • Yes? Add it to the \`addTests()\` array. • No? The \`${detectName}\` detection is wrong and should be fixed. `), ); diff --git a/index.ts b/index.ts index eccd5d25..ec696cdd 100644 --- a/index.ts +++ b/index.ts @@ -757,6 +757,16 @@ export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boo || isCompareWikiPage(url) || isBlame(url); +TEST: addTests('isRepoGitObject', [ + 'isRepoTree', + 'isSingleFile', + 'isBlame', +]); +/** Covers blob, trees and blame pages */ +export const isRepoGitObject = (url: URL | HTMLAnchorElement | Location = location): boolean => + isRepo(url) + && [undefined, 'blob', 'tree', 'blame'].includes(getCleanPathname(url).split('/')[2]); + TEST: addTests('hasFiles', combinedTestOnly); /** Has a list of files */ export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean =>