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

Use API for bypass-checks #3629

Merged
merged 10 commits into from Oct 9, 2020
19 changes: 10 additions & 9 deletions source/features/bypass-checks.tsx
@@ -1,19 +1,20 @@
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';
import * as api from '../github-helpers/api';
import {getRepoURL} from '../github-helpers';

async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
const directLink = await fetchDom<HTMLAnchorElement>(
detailsLink.href,
'[data-hydro-click*="check_suite.external_click"]'
);
const getDirectLink = mem(async (runId: number): Promise<string> => {
Copy link
Member

@fregante fregante Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API is already memoized, no need to do it again. You can probably just inline it like it was

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed from there too. It would only make sense if it saved heavy operations (e.g. HTTP requests), but what follows is just a few conditions.

const directLink = await api.v3(`repos/${getRepoURL()}/check-runs/${runId}`);
return directLink.details_url;
});

if (directLink) {
detailsLink.href = directLink.href;
}
async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
const runId = new URLSearchParams(detailsLink.href).get('check_run_id') ?? detailsLink.pathname.split('/').pop();
yakov116 marked this conversation as resolved.
Show resolved Hide resolved
detailsLink.href = await getDirectLink(Number(runId));
}

function init(): void {
Expand Down