Skip to content

Commit 014d27b

Browse files
authored
Add isPRCommit404 detection (#12)
1 parent 6fbc3e2 commit 014d27b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ collect.set('isPRCommit', [
189189
'https://github.com/sindresorhus/refined-github/pull/148/commits/00196',
190190
]);
191191

192+
export const isPRCommit404 = (): boolean => isPRCommit() && document.title.startsWith('Commit range not found · Pull Request');
193+
192194
export const isPRConversation = (url: URL | Location = location): boolean => /^pull\/\d+$/.test(getRepoPath(url)!);
193195
collect.set('isPRConversation', [
194196
'https://github.com/sindresorhus/refined-github/pull/148',

test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import collector from './collector';
77
const {window} = new JSDOM('…');
88

99
(global as any).document = window.document;
10+
(global as any).location = new URL('https://github.com/');
1011

1112
const allUrls = new Set<string>([...collector.values()].flat());
1213
allUrls.delete('combinedTestOnly');
@@ -96,6 +97,20 @@ test('is500', t => {
9697
t.false(pageDetect.is500());
9798
});
9899

100+
test('isPRCommit404', t => {
101+
document.title = 'Commit range not found · Pull Request #3227 · sindresorhus/refined-github';
102+
location.href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/32c8a88360a85739f151566eae0225d530ce6a15';
103+
t.true(pageDetect.isPRCommit404());
104+
105+
document.title = 'Experiment with `@primer/octicons-react` icons by FloEdelmann · Pull Request #3227 · sindresorhus/refined-github';
106+
location.href = 'https://github.com/sindresorhus/refined-github/pull/3227/commits/edbdcdd5559a2a8da78abdc7cb0814155713974c';
107+
t.false(pageDetect.isPRCommit404());
108+
109+
document.title = 'Commit range not found by SomeContributor · Pull Request #999999 · sindresorhus/refined-github';
110+
location.href = 'https://github.com/sindresorhus/refined-github/pull/999999/commits/32c8a88360a85739f151566eae0225d530ce6a15';
111+
t.false(pageDetect.isPRCommit404());
112+
});
113+
99114
test('getRepoPath', t => {
100115
const pairs = new Map<string, string | undefined>([
101116
[

0 commit comments

Comments
 (0)