Slight refactoring

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 396bcc497e
commit 945426d2e8
  1. 44
      BuildServer/lib/report-processor.js

@ -5,12 +5,28 @@ const fs = require("fs");
const glob = require("glob"); const glob = require("glob");
const _ = require("underscore"); const _ = require("underscore");
exports.writeReport = (releasePath, err, result, callback) => fs.writeFile(path.join(releasePath, "report.json"), JSON.stringify({ const writeReport = (releaseDir, err, result, callback) => fs.writeFile(path.join(releaseDir, "report.json"), JSON.stringify({
"date": Date.now(), "date": Date.now(),
err, err,
result result
}), callback); }), callback);
const readReport = (releaseDir, callback) => fs.readFile(path.join(releaseDir, "report.json"), (err, dataBuffer) => {
if (err) {
return callback(err);
}
const data = dataBuffer.toString();
if (!data) {
return callback("ReportFileNotFound");
}
return callback(null, JSON.parse(data));
});
exports.writeReport = writeReport;
exports.loadReport = (app, options, callback) => { exports.loadReport = (app, options, callback) => {
const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev); const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
@ -31,17 +47,12 @@ exports.loadReport = (app, options, callback) => {
return callback("ReportFileNotFound", options); return callback("ReportFileNotFound", options);
} }
return fs.readFile(reportFile, (readErr, dataBuffer) => { return readReport(releaseDir, (readErr, report) => {
if (readErr) { if (readErr) {
return callback(readErr, options); return callback(readErr, options);
} }
const data = dataBuffer.toString(); options.report = report;
if (!data) {
return callback("ReportFileNotFound", options);
}
options.report = JSON.parse(data);
return callback(null, options); return callback(null, options);
}); });
@ -70,22 +81,15 @@ exports.getStatusMessageFromRelease = (app, options, callback) => {
}), 2000); }), 2000);
} }
return setTimeout(() => fs.readFile(reportFile, (err, dataBuffer) => { return setTimeout(() => readReport(releaseDir, (readErr, report) => {
if (err) { if (readErr) {
return callback(err); return callback(readErr);
}
const data = dataBuffer.toString();
if (!data) {
return callback("Report file not found");
} }
const report = JSON.parse(data);
if (report.result === "MBSNotFound") { if (report.result === "MBSNotFound") {
return callback("mbs.json is not found"); return callback("mbs.json is not found");
} }
if (report.result && ((report.result.errors || {}).$allMessages || []).length + ((report.result.warns || {}).$allMessages || []).length > 0) { if (report.result && ((report.result.errors || {}).$allMessages || []).length + ((report.result.warns || {}).$allMessages || []).length > 0) {
return callback(_.map( return callback(_.map(
(report.result.errors || {}).$allMessages || [], (message) => `ERR: ${message.message}` (report.result.errors || {}).$allMessages || [], (message) => `ERR: ${message.message}`
@ -94,9 +98,11 @@ exports.getStatusMessageFromRelease = (app, options, callback) => {
)) ))
.join("\r\n")); .join("\r\n"));
} }
if (!report.result || report.err) { if (!report.result || report.err) {
return callback(`CRITICAL ERROR: ${report.err}`); return callback(`CRITICAL ERROR: ${report.err}`);
} }
if ((report.result.infos.$allMessages || []).length > 0) { if ((report.result.infos.$allMessages || []).length > 0) {
return callback(null, report.result.infos.$allMessages[report.result.infos.$allMessages.length - 1].message); return callback(null, report.result.infos.$allMessages[report.result.infos.$allMessages.length - 1].message);
} }

Loading…
Cancel
Save