Skip to content

Add isRepoGitObject #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
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
6 changes: 3 additions & 3 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()\``,
);
});

Expand All @@ -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.
`),
);
});
Expand All @@ -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.
`),
);
Expand Down
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down