Created
November 19, 2015 16:08
-
-
Save xavhan/19dad4e82f2a25edd817 to your computer and use it in GitHub Desktop.
Circle CI status + karma-coverage link
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 REPO = 'githubUsername/repoName'; | |
var TOKEN = 'token'; | |
getCircleStatus(TOKEN, REPO); | |
function getCircleStatus() { | |
var endpoint = 'project/' + REPO; | |
httpGetAsync(endpoint, printStatus) | |
} | |
function getCoverage(idBuild) { | |
var endpoint = 'project/' + REPO + '/' + idBuild + '/artifacts' | |
httpGetAsync(endpoint, printLink) | |
} | |
function httpGetAsync(endpoint, callback) { | |
var api = 'https://circleci.com/api/v1/'; | |
var auth = '?circle-token=' + TOKEN + '&Accept=application/json'; | |
var url = api + endpoint + token; | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.onreadystatechange = function() { | |
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) | |
callback(xmlHttp.responseText); | |
} | |
xmlHttp.open("GET", api + endpoint + auth, true); // true for asynchronous | |
xmlHttp.setRequestHeader("Accept", "application/json"); | |
xmlHttp.send(null); | |
} | |
function printStatus(circleAnswer){ | |
var status = JSON.parse(circleAnswer)[0].status | |
if (status === 'failed') { | |
console.log('%c 😱 Build has failded :( ' + JSON.parse(circleAnswer)[0].build_url, 'color:red'); | |
} else { | |
console.log('%c 😘 Build has Swag', 'color:green'); | |
} | |
getCoverage(JSON.parse(circleAnswer)[0].build_num); | |
} | |
function printLink(circleAnswer) { | |
console.log(JSON.parse(circleAnswer)[6].url); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment