Enhance the travis script

This commit is contained in:
pancake 2017-09-03 00:31:54 +02:00
parent cd7f70fc4e
commit 2ac31bcf2f

View File

@ -1,6 +1,7 @@
const get = require('simple-get');
const path = require('path');
const colors = require('colors');
const fs = require('fs');
const travisUrl = 'https://api.travis-ci.org';
const travisPath = 'radare/radare2';
@ -27,31 +28,71 @@ async function travis(api, root, cb) {
function parseLogs(log) {
const obj = {
txt: '',
fx: 0,
xx: 0,
br: 0
br: 0,
issues: []
};
if (log)
for (let line of log.replace('\r', '').split('\n')) {
if (line.indexOf('XX]') !== -1) {
obj.xx++;
if (log) {
let issue = '';
let issueFound = false;
let last = '';
for (let line of log.split('\n')) {
function pun() {
issueFound = false;
if (issue.length > 0) {
obj.issues.push('issue');
}
issue = '';
}
/*
if (issueFound) {
pun();
issue += line;
}
*/
if (line.indexOf('FX]') !== -1) {
obj.fx++;
}
if (line.indexOf('XX]') !== -1) {
obj.xx++;
// issueFound = true;
// issue += last + '\n';
} else if (line.indexOf('BR]') !== -1) {
obj.br++;
// issueFound = false;
// pun();
}
// issue += line + '\n';
// obj.txt += line + '\n';
last = line;
}
if (line.indexOf('BR]') !== -1) {
obj.br++;
}
obj.txt += line + '\n';
}
obj.issues = obj.issues.length;
return obj;
}
async function processJob(job) {
console.log(colors.green(`[BUILD] ${job.id} ${job.message}`));
console.log(colors.yellow(`[TSTMP] ${job.id} ${job.started_at}`));
console.log(colors.yellow(`[COMIT] ${job.id} ${job.commit}`));
console.log(colors.green(`[BUILD] ${job.id} (${job.state}) ${job.message}`));
console.log(colors.yellow(`[-----] ${job.id} ${job.started_at} ${job.commit}`));
const buildInfo = await travis('builds/' + job.id, false);
for (let job of buildInfo.matrix) {
const travisLog = await travis(`jobs/${job.id}`, false);
const result = parseLogs(travisLog.log);
console.log(' [JOB]', job.id, 'XX:', result.xx, 'BR:', result.br);
const logFile = 'log-' + job.id + '.txt';
const logExists = fs.existsSync(logFile);
const travisLog = logExists
? { log: fs.readFileSync(logFile).toString() }
: await travis(`jobs/${job.id}`, false);
const log = (travisLog && travisLog.log)? travisLog.log.replace('\r', ''): '';
const result = parseLogs(log);
if (!logExists) {
fs.writeFileSync(logFile, log);
}
console.log(' [JOB]', job.id, 'XX:', result.xx, 'BR:', result.br, 'FX:', result.fx);
/*
for (let issue of result.issues) {
// console.log(' - ', issue);
}
*/
}
}
@ -69,4 +110,8 @@ async function main() {
}
}
main().then(process.exit).catch(console.error);
if (process.argv.length > 2) {
console.log(parseLogs(fs.readFileSync(process.argv[2]).toString()));
} else {
main().then(process.exit).catch(console.error);
}