Created
September 12, 2017 18:56
-
-
Save benjaminwood/e47a8e6383dcb96c6dc5f65808a90f8a to your computer and use it in GitHub Desktop.
This file contains 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 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); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was written quickly and needs refactoring. Anybody that uses it, feel free to improve and post here in the comments.