Skip to content

Commit

Permalink
Add isPRFile404 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakov116 committed Jul 7, 2020
1 parent 412259b commit 63005a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ collect.set('isPRCommit', [
]);

export const isPRCommit404 = (): boolean => isPRCommit() && document.title.startsWith('Commit range not found · Pull Request');
export const isPRFile404 = (): boolean => isPRFiles() && document.title.startsWith('Commit range not found · Pull Request');

export const isPRConversation = (url: URL | Location = location): boolean => /^pull\/\d+$/.test(getRepoPath(url)!);
collect.set('isPRConversation', [
Expand Down
10 changes: 10 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ test('isPRCommit404', t => {
t.false(pageDetect.isPRCommit404());
});

test('isPRFile404', t => {
document.title = 'Commit range not found · Pull Request #789 · sindresorhus/eslint-plugin-unicorn';
location.href = 'https://github.com/sindresorhus/eslint-plugin-unicorn/pull/789/files/a58b37845f1b2660221de019e4ae6c736feedc26..eed168224d7994652b1d1ff69a5c8cebee223faf';
t.true(pageDetect.isPRFile404());

document.title = 'Add `align-repository-header` feature by fregante · Pull Request #3313 · sindresorhus/refined-github';
location.href = 'https://github.com/sindresorhus/refined-github/pull/3313/files/a14fb2c94eae3ca83a3a97688a171fcc3405524f..fbeeba9825f12b5ded9cd4bb04d5df4b0cf2f2a8';
t.false(pageDetect.isPRFile404());
});

test('getRepoPath', t => {
const pairs = new Map<string, string | undefined>([
[
Expand Down

0 comments on commit 63005a4

Please sign in to comment.