Skip to content

Commit cda5f6c

Browse files
authored
Add isRepoGitObject (#207)
1 parent f7a3c74 commit cda5f6c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
2424
test(detectName + ' has tests', () => {
2525
assert.ok(
2626
Array.isArray(validURLs),
27-
`The function \`${detectName}\` doesn’t have any tests. Set them via \`collect.set()\``,
27+
`The function \`${detectName}\` doesn’t have any tests. Set them via \`addTests()\``,
2828
);
2929
});
3030

@@ -41,7 +41,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
4141
${url.replace('https://github.com', '')}
4242
4343
• Yes? The \`${detectName}\` detection is wrong and should be fixed.
44-
• No? Remove it from its \`collect.set()\` array.
44+
• No? Remove it from its \`addTests()\` array.
4545
`),
4646
);
4747
});
@@ -62,7 +62,7 @@ for (const [detectName, detect] of Object.entries(pageDetect)) {
6262
Is this URL \`${detectName}\`?
6363
${url.replace('https://github.com', '')}
6464
65-
• Yes? Add it to the \`collect.set()\` array.
65+
• Yes? Add it to the \`addTests()\` array.
6666
• No? The \`${detectName}\` detection is wrong and should be fixed.
6767
`),
6868
);

index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,16 @@ export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boo
757757
|| isCompareWikiPage(url)
758758
|| isBlame(url);
759759

760+
TEST: addTests('isRepoGitObject', [
761+
'isRepoTree',
762+
'isSingleFile',
763+
'isBlame',
764+
]);
765+
/** Covers blob, trees and blame pages */
766+
export const isRepoGitObject = (url: URL | HTMLAnchorElement | Location = location): boolean =>
767+
isRepo(url)
768+
&& [undefined, 'blob', 'tree', 'blame'].includes(getCleanPathname(url).split('/')[2]);
769+
760770
TEST: addTests('hasFiles', combinedTestOnly);
761771
/** Has a list of files */
762772
export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean =>

0 commit comments

Comments
 (0)