Skip to content

Instantly share code, notes, and snippets.

@xavhan
Created November 19, 2015 16:08
Show Gist options
  • Save xavhan/19dad4e82f2a25edd817 to your computer and use it in GitHub Desktop.
Save xavhan/19dad4e82f2a25edd817 to your computer and use it in GitHub Desktop.
Circle CI status + karma-coverage link
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