-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ci-link.tsx
39 lines (34 loc) · 1.05 KB
/
ci-link.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
import './ci-link.css';
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';
import features from '.';
import fetchDom from '../helpers/fetch-dom';
import {buildRepoURL} from '../github-helpers';
// Look for the CI icon in the latest 2 days of commits #2990
const getIcon = onetime(async () => fetchDom(
buildRepoURL('commits'), [
'.TimelineItem--condensed:nth-of-type(-n+2) .commit-build-statuses', // TODO[2022-04-29]: GHE
'.TimelineItem--condensed:nth-of-type(-n+2) batch-deferred-content[data-url$="checks-statuses-rollups"]'
].join()
));
async function init(): Promise<false | void> {
const icon = await getIcon();
if (!icon) {
return false;
}
// Append to title (aware of forks and private repos)
const repoNameHeader = select('[itemprop="name"]')!.parentElement!;
repoNameHeader.append(icon);
repoNameHeader.classList.add('rgh-ci-link');
}
void features.add(__filebasename, {
include: [
pageDetect.isRepo
],
exclude: [
pageDetect.isEmptyRepo
],
awaitDomReady: false,
init
});