-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
bypass-checks.tsx
45 lines (39 loc) · 1.6 KB
/
bypass-checks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import mem from 'mem';
import onetime from 'onetime';
import {observe} from 'selector-observer';
import * as pageDetect from 'github-url-detection';
import features from '.';
import * as api from '../github-helpers/api';
import {getRepositoryInfo} from '../github-helpers';
const getDirectLink = mem(async (runNumber: number): Promise<string> => {
const directLink = await api.v3(`https://api.github.com/repos/${getRepositoryInfo()!.owner!}/${getRepositoryInfo()!.name!}/check-runs/${runNumber}`);
return directLink.details_url;
});
async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
const runNumber = detailsLink.href.split(/\/|=/).pop();
detailsLink.href = await getDirectLink(Number(runNumber));
}
function init(): void {
// This selector excludes URLs that are already external
const thirdPartyApps = [
`a:not([href="/apps/github-actions"]) ~ div .status-actions[href^="${location.origin}"]:not(.rgh-bypass-link)`, // Hovercard status checks
'a:not([href="/apps/github-actions"]) ~ div .status-actions[href^="/"]:not(.rgh-bypass-link)'
].join();
observe(thirdPartyApps, {
constructor: HTMLAnchorElement,
add(thirdPartyApp) {
thirdPartyApp.classList.add('rgh-bypass-link');
void bypass(thirdPartyApp);
}
});
}
void features.add({
id: __filebasename,
description: 'Bypasses the "Checks" interstitial when clicking the "Details" links on a PR Checks added by third-party services like Travis.',
screenshot: 'https://user-images.githubusercontent.com/2103975/49071220-c6596e80-f22d-11e8-8a1e-bdcd62aa6ece.png'
}, {
include: [
pageDetect.isPRConversation
],
init: onetime(init)
});