Skip to content

Instantly share code, notes, and snippets.

@dariusf
Last active Oct 10, 2015
Embed
What would you like to do?
var PASSED = 'passed',
STARTED = 'started',
FAILED = 'failed',
ERRORED = 'errored',
CANCELED = 'canceled',
POLL_PERIOD = 5000,
MAX_MINUTES = 22;
function icon(which) {
return $('.icon.icon-status.' + which + '[title="' + which + '"]')
}
function has(which) {
return icon(which).length > 0;
}
var hasBeen = has;
function restartBuild() {
console.log('Restarted build!');
$('.button-circle[title="Restart Build"]').click();
}
function cancelBuild() {
console.log('Canceled build!');
$('.button-circle[title="Cancel Build"]').click();
}
function elapsedMinutes() {
var timeString = $('div.tile-additional > ul.repo-main-info > li[title]').first().attr('title');
var match = /(\d+) min \d+ sec/g.exec(timeString);
return match ? +match[1] : 0;
}
function win() {
alert(PASSED);
document.title = PASSED;
console.log('Passed!');
}
(function pollUntilSuccess() {
if (has(PASSED)) {
return win();
}
if (has(FAILED) || has(ERRORED) || hasBeen(CANCELED)) {
restartBuild();
} else if (elapsedMinutes() > MAX_MINUTES) {
cancelBuild();
} else {
console.log('Waiting...');
}
setTimeout(pollUntilSuccess, POLL_PERIOD);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment