Skip to content

Commit 457071f

Browse files
authored
Adds build status and link to CI next to the repo's title (refined-github#800)
1 parent 4a2185f commit 457071f

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

extension/content.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,19 @@ a.tabnav-extra[href$="mastering-markdown/"] {
674674
display: none;
675675
}
676676

677+
/* For `add-ci-link` */
678+
.rgh-ci-link {
679+
position: relative;
680+
top: -0.1em;
681+
left: 0.2em;
682+
animation: fade-in 0.2s;
683+
}
684+
685+
:root .repohead h1 .octicon {
686+
position: static;
687+
color: inherit;
688+
}
689+
677690
/* Sticky file headers on pull request diff view */
678691
.pull-request-tab-content .diff-view .file-header {
679692
position: sticky;

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ GitHub Enterprise is also supported by [authorizing your own domain in the optio
127127
- [Shows user's full name in comments](https://cloud.githubusercontent.com/assets/170270/16172068/0a67b98c-3580-11e6-92f0-6fc930ee17d1.png)
128128
- [Differentiates merge commits from regular commits](https://cloud.githubusercontent.com/assets/170270/14101222/2fe2c24a-f5bd-11e5-8b1f-4e589917d4c4.png)
129129
- [Adds labels to comments by the original poster](https://cloud.githubusercontent.com/assets/4331946/25075520/d62fbbd0-2316-11e7-921f-ab736dc3522e.png)
130+
- [Adds build status and link to CI by the repo's title](https://user-images.githubusercontent.com/1402241/32562120-d65166e4-c4e8-11e7-90fb-cbaf36e2709f.png)
130131

131132
### Declutter
132133

src/content.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import openCIDetailsInNewTab from './features/open-ci-details-in-new-tab';
4848
import focusConfirmationButtons from './features/focus-confirmation-buttons';
4949
import addKeyboardShortcutsToCommentFields from './features/add-keyboard-shortcuts-to-comment-fields';
5050
import addConfirmationToCommentCancellation from './features/add-confirmation-to-comment-cancellation';
51+
import addCILink from './features/add-ci-link';
5152

5253
import * as pageDetect from './libs/page-detect';
5354
import {observeEl, safeElementReady, safely} from './libs/utils';
@@ -150,6 +151,7 @@ function ajaxedPagesHandler() {
150151
safely(addReadmeButtons);
151152
safely(addDiffViewWithoutWhitespaceOption);
152153
safely(removeDiffSigns);
154+
safely(addCILink);
153155
safely(sortMilestonesByClosestDueDate); // Needs to be after addMilestoneNavigation
154156
}
155157

src/features/add-ci-link.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import select from 'select-dom';
2+
import domify from '../libs/domify';
3+
import {getRepoURL} from '../libs/page-detect';
4+
5+
// This var will be:
6+
// - undefined on first load
7+
// - a Promised dom element after a successful fetch
8+
// - false after a failed fetch
9+
let request;
10+
11+
async function fetchStatus() {
12+
const url = `${location.origin}/${getRepoURL()}/commits/`;
13+
const dom = await fetch(url).then(r => r.text()).then(domify);
14+
15+
const icon = select('.commit-build-statuses', dom);
16+
17+
// This will error if the element isn't found.
18+
// It's caught later.
19+
icon.classList.add('rgh-ci-link');
20+
21+
return icon;
22+
}
23+
24+
export default async function () {
25+
// Avoid duplicates and avoid on pages that already failed to load
26+
if (request === false || select.exists('.rgh-ci-link')) {
27+
return;
28+
}
29+
30+
try {
31+
if (request) {
32+
// Skip icon re-animation because
33+
// it was probably already animated once
34+
(await request).style.animation = 'none';
35+
} else {
36+
request = fetchStatus();
37+
}
38+
select('.pagehead [itemprop="name"]').append(await request);
39+
} catch (err) {
40+
// Network failure or no CI status found.
41+
// Don’t try again
42+
request = false;
43+
}
44+
}

0 commit comments

Comments
 (0)