Skip to content
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

Enable bypass-checks on more commit statuses #3610

Merged
merged 4 commits into from
Oct 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions source/features/bypass-checks.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import select from 'select-dom';
import mem from 'mem';
import onetime from 'onetime';
import {observe} from 'selector-observer';
import * as pageDetect from 'github-url-detection';

import features from '.';
import fetchDom from '../helpers/fetch-dom';

async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
const bypass = mem(async (detailsLink: HTMLAnchorElement): Promise<void> => {
fregante marked this conversation as resolved.
Show resolved Hide resolved
const directLink = await fetchDom<HTMLAnchorElement>(
detailsLink.href,
'[data-hydro-click*="check_suite.external_click"]'
Expand All @@ -13,14 +15,22 @@ async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
if (directLink) {
detailsLink.href = directLink.href;
}
}
});

async function init(): Promise<void> {
// This selector excludes URLs that are already external
const thirdPartyApps = select.all<HTMLAnchorElement>('a:not([href="/apps/github-actions"]) ~ div .status-actions[href^="/"]');
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();

// If anything errors, RGH will display the error next to the feature name
await Promise.all(thirdPartyApps.map(bypass));
observe(thirdPartyApps, {
constructor: HTMLAnchorElement,
async add(thirdPartyApp) {
thirdPartyApp.classList.add('rgh-bypass-link');
await bypass(thirdPartyApp);
fregante marked this conversation as resolved.
Show resolved Hide resolved
}
});
}

void features.add({
Expand All @@ -31,5 +41,5 @@ void features.add({
include: [
pageDetect.isPRConversation
],
init
init: onetime(init)
});