Skip to content

Instantly share code, notes, and snippets.

@dariusf
Last active October 10, 2015 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariusf/82cab9f652828fcbee0e to your computer and use it in GitHub Desktop.
Save dariusf/82cab9f652828fcbee0e to your computer and use it in GitHub Desktop.
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