Skip to content

Commit 87957a1

Browse files
authored
Merge branch 'main' into pathParts
2 parents d49c55c + 87548d2 commit 87957a1

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

index.test.ts

Lines changed: 3 additions & 3 deletions
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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ export const isOwnUserProfile = (): boolean => getCleanPathname() === getLoggedI
202202
// If there's a Report Abuse link, we're not part of the org
203203
export const isOwnOrganizationProfile = (): boolean => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
204204

205-
export const isProject = (url: URL | HTMLAnchorElement | Location = location): boolean => /^projects\/\d+/.test(getRepo(url)?.path);
205+
export const isProject = (url: URL | HTMLAnchorElement | Location = location): boolean => /^projects\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
206206
TEST: addTests('isProject', [
207207
'https://github.com/sindresorhus/refined-github/projects/3',
208+
'https://github.com/orgs/RSSNext/projects/3',
208209
]);
209210

210211
export const isProjects = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'projects';
@@ -253,10 +254,13 @@ TEST: addTests('isPRList', [
253254
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed',
254255
]);
255256

256-
export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
257+
export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path);
257258
TEST: addTests('isPRCommit', [
258-
'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
259-
'https://github.com/sindresorhus/refined-github/pull/148/commits/00196',
259+
'https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641',
260+
'https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79',
261+
// Since December 2025
262+
'https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641',
263+
'https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79',
260264
]);
261265

262266
export const isPRCommit404 = (): boolean => isPRCommit() && document.title.startsWith('Commit range not found · Pull Request');
@@ -272,12 +276,16 @@ TEST: addTests('isPRCommitList', [
272276
'https://github.com/sindresorhus/refined-github/pull/148/commits',
273277
]);
274278

275-
export const isPRFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
279+
export const isPRFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/(files|(changes(\/[\da-f]{7,40}..[\da-f]{7,40})?$))/.test(getRepo(url)?.path) || isPRCommit(url);
276280
TEST: addTests('isPRFiles', [
277281
'isPRCommit', // File contents but lacks "Viewed" checkbox, has commit information
278282
'https://github.com/sindresorhus/refined-github/pull/148/files',
279283
'https://github.com/sindresorhus/refined-github/pull/148/files/e1aba6f', // This means "every commit until e1aba6f"
280284
'https://github.com/sindresorhus/refined-github/pull/148/files/1e27d799..e1aba6f', // This means specifically "Between commit A and B"
285+
// Since December 2025
286+
'https://github.com/refined-github/refined-github/pull/148/changes',
287+
'https://github.com/refined-github/refined-github/pull/148/changes/1e27d799..e1aba6f', // This means specifically "Between commit A and B"
288+
'https://github.com/refined-github/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641..e1aba6febb3fe38aafd1137cff28b536eeeabe7e',
281289
]);
282290

283291
export const isQuickPR = (url: URL | HTMLAnchorElement | Location = location): boolean => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
@@ -613,6 +621,11 @@ TEST: addTests('isRepoNetworkGraph', [
613621

614622
export const isForkedRepo = (): boolean => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]');
615623

624+
export const isForkingRepo = (url: URL | HTMLAnchorElement | Location = location): boolean => getRepo(url)?.path === 'fork';
625+
TEST: addTests('isForkingRepo', [
626+
'https://github.com/refined-github/refined-github/fork',
627+
]);
628+
616629
export const isSingleGist = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url));
617630
TEST: addTests('isSingleGist', [
618631
'https://gist.github.com/fregante/2205329b71218fa2c1d3',
@@ -757,6 +770,16 @@ export const hasCode = (url: URL | HTMLAnchorElement | Location = location): boo
757770
|| isCompareWikiPage(url)
758771
|| isBlame(url);
759772

773+
TEST: addTests('isRepoGitObject', [
774+
'isRepoTree',
775+
'isSingleFile',
776+
'isBlame',
777+
]);
778+
/** Covers blob, trees and blame pages */
779+
export const isRepoGitObject = (url: URL | HTMLAnchorElement | Location = location): boolean =>
780+
isRepo(url)
781+
&& [undefined, 'blob', 'tree', 'blame'].includes(getCleanPathname(url).split('/')[2]);
782+
760783
TEST: addTests('hasFiles', combinedTestOnly);
761784
/** Has a list of files */
762785
export const hasFiles = (url: URL | HTMLAnchorElement | Location = location): boolean =>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-url-detection",
3-
"version": "10.0.1",
3+
"version": "10.2.3",
44
"description": "Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.",
55
"keywords": [
66
"github",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.
44
5-
Battle-tested by and extracted from the [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.
5+
Battle-tested in [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.
66

77
- Try the live [demo](https://refined-github.github.io/github-url-detection/)
88
- See the code and expected URLs for [every detection](https://github.com/refined-github/github-url-detection/blob/main/index.ts)

0 commit comments

Comments
 (0)