Last active
October 10, 2015 09:45
-
-
Save dariusf/82cab9f652828fcbee0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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