Skip to content

Instantly share code, notes, and snippets.

@benjaminwood
Created September 12, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminwood/e47a8e6383dcb96c6dc5f65808a90f8a to your computer and use it in GitHub Desktop.
Save benjaminwood/e47a8e6383dcb96c6dc5f65808a90f8a to your computer and use it in GitHub Desktop.
var logLocationInforation = [];
var logs = [];
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', URL.createObjectURL(new Blob([text], {type: "application/octet-stream"})));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}
}
function getPipelines() { return $('*div[data-pipelines]').first().data('pipelines'); }
function fetchLogLocationInformation(pipelines) {
return pipelines.map(function(pipeline) {
var orderedSteps = pipeline.steps.reverse();
var testStep = orderedSteps[0]
return $.get('https://app.codeship.com' + testStep.log_path + '.json').then(function(data){
logLocationInforation.push({ name: pipeline.name, logPath: data.url });
})
})
}
function fetchLogs(logLocationInforation) {
return logLocationInforation.map(function(logInfo) {
return $.get(logInfo.logPath).then(function(data){
logs.push({ name: logInfo.name, data: data });
})
})
}
var pipelines = getPipelines();
var logLocationInformationPromises = fetchLogLocationInformation(pipelines);
$.when.apply($, logLocationInformationPromises).done(function() {
var logPromises = fetchLogs(logLocationInforation)
$.when.apply($, logPromises).done(function() {
combinedLog = ''
ansiRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
logs.forEach(function(log) {
combinedLog = combinedLog + log.name + '\n\n';
combinedLog = combinedLog + log.data.replace(ansiRegex, '') + '\n\n';
})
download('combinedLog.log', combinedLog);
})
})
@benjaminwood
Copy link
Author

This was written quickly and needs refactoring. Anybody that uses it, feel free to improve and post here in the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment