Skip to content

Instantly share code, notes, and snippets.

@menshikh-iv
Created January 8, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menshikh-iv/bfe9b8ef2db10e9511aa9fe5935a7289 to your computer and use it in GitHub Desktop.
Save menshikh-iv/bfe9b8ef2db10e9511aa9fe5935a7289 to your computer and use it in GitHub Desktop.
Greasemonkey script that adds a button to the PR page to open the doc generated by CircleCI for this PR
// ==UserScript==
// @name see PR doc on CircleCI
// @namespace lesteve
// @include /https://github.com/RaRe-Technologies/gensim/pull/[0-9]+[^/]*$/
// @grant none
// ==/UserScript==
(function(){
'use strict';
// console.log('Running user script');
window.addEventListener('load', () => {
addButton('See CircleCI doc for this PR', gotoCirclePage);
});
function addButton(text, onclick, cssObj) {
let headerActionElement = document.getElementsByClassName('gh-header-actions')[0];
// console.log('headerActionElement', headerActionElement);
cssObj = cssObj || {};
let button = document.createElement('button'), btnStyle = button.style;
headerActionElement.appendChild(button);
button.innerHTML = text;
button.onclick = onclick;
button.classList = "btn btn-sm";
button.type = "button";
Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key]);
return button;
}
function findElementsBySelectorAndText(selector, text) {
var elements = document.querySelectorAll(selector);
return Array.prototype.filter.call(elements, function(element){
return RegExp(text).test(element.textContent);
});
}
function gotoCirclePage() {
var circleElement;
var useCircleWorkflow;
circleElement = findElementsBySelectorAndText('.branch-action .merge-status-item', 'ci/circle.+python3')[0];
if (!circleElement) {
circleElement = findElementsBySelectorAndText('.branch-action .merge-status-item', 'ci/circle')[0];
}
var match = /circleci.com\/.*?([0-9]+)\?/.exec(circleElement.innerHTML);
if (match) {
var circleBuildNumber = match[1];
var docURLPart;
docURLPart = "-1349775-gh.circle-artifacts.com/0/documentation/html/index.html"
var docURL = 'https://' + circleBuildNumber + docURLPart;
window.open(docURL);
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment