All report.json processing functionality moved out to report-processor

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 7 years ago
parent 40a9f6c691
commit 396bcc497e
  1. 7
      BuildServer/lib/builder.js
  2. 63
      BuildServer/lib/commenter.js
  3. 107
      BuildServer/lib/report-processor.js
  4. 42
      BuildServer/lib/status-processor.js

@ -6,6 +6,7 @@ const fse = require("fs-extra");
const async = require("async");
const gitLoader = require("./git/loader");
const processor = require("./task-processor");
const reportProcessor = require("./report-processor");
const mailSender = require("./mail-sender");
const settings = require("../settings");
@ -81,11 +82,7 @@ const build = (options, callback) => {
? ((result.infos.$allMessages || []).slice(-1)[0] || {}).message
: err;
fs.writeFile(path.join(release, "report.json"), JSON.stringify({
"date": Date.now(),
err,
result
}), (writeErr) => {
reportProcessor.writeReport(release, err, result, (writeErr) => {
statusQueue.push((callback) => async.parallel([
(callback) => notifyStatus({
"description": errorMessage || warnMessage || infoMessage || "Success",

@ -1,8 +1,6 @@
"use strict";
const path = require("path");
const fs = require("fs");
const _ = require("underscore");
const reportProcessor = require("./report-processor");
const settings = require("../settings");
const featureNamePattern = /^feature-(\d+)(?:-[a-zA-Z0-9]+)+$/;
@ -134,67 +132,10 @@ const checkPullRequest = (options, callback) => {
});
};
const getStatusMessageFromRelease = (app, options, callback) => {
const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
const reportFile = path.join(releaseDir, "/report.json");
options.attemptsGetReport = (options.attemptsGetReport || 0) + 1;
fs.exists(reportFile, (exists) => {
if (!exists) {
return setTimeout(() => fs.exists(releaseDir, (dirExists) => {
if (!dirExists) {
return callback("Release directory not found. Probably repository hooks are not configured");
}
if (options.attemptsGetReport > 100) {
return callback("Report file not found");
}
// Maybe it is building right now
return setTimeout(() => getStatusMessageFromRelease(app, options, callback), 10000);
}), 2000);
}
return setTimeout(() => fs.readFile(reportFile, (err, dataBuffer) => {
if (err) {
return callback(err);
}
const data = dataBuffer.toString();
if (!data) {
return callback("Report file not found");
}
const report = JSON.parse(data);
if (report.result === "MBSNotFound") {
return callback("mbs.json is not found");
}
if (report.result && ((report.result.errors || {}).$allMessages || []).length + ((report.result.warns || {}).$allMessages || []).length > 0) {
return callback(_.map(
(report.result.errors || {}).$allMessages || [], (message) => `ERR: ${message.message}`
).concat(_.map(
(report.result.warns || {}).$allMessages || [], (message) => `WARN: ${message.message}`
))
.join("\r\n"));
}
if (!report.result || report.err) {
return callback(`CRITICAL ERROR: ${report.err}`);
}
if ((report.result.infos.$allMessages || []).length > 0) {
return callback(null, report.result.infos.$allMessages[report.result.infos.$allMessages.length - 1].message);
}
return callback(null, "OK");
}), 1000);
});
};
exports.commentOnPullRequest = (options, callback) => {
options.github = settings.createGithub(options.baseRepoOptions.owner);
return checkPullRequest(options, (err, successMessage) => getStatusMessageFromRelease(options.app, options.headRepoOptions, (err, successMessage) => {
return checkPullRequest(options, (err, successMessage) => reportProcessor.getStatusMessageFromRelease(options.app, options.headRepoOptions, (err, successMessage) => {
const escapedErr = (err || "").substring(0, 64000).replace(/`/g, "` ");
const message = err
? `Was not built:\r\n\r\n\`\`\`\r\n${escapedErr}\r\n\`\`\`\r\n\r\nDO NOT MERGE!`

@ -0,0 +1,107 @@
"use strict";
const path = require("path");
const fs = require("fs");
const glob = require("glob");
const _ = require("underscore");
exports.writeReport = (releasePath, err, result, callback) => fs.writeFile(path.join(releasePath, "report.json"), JSON.stringify({
"date": Date.now(),
err,
result
}), callback);
exports.loadReport = (app, options, callback) => {
const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
glob("**", {
"cwd": releaseDir,
"mark": true
}, (err, files) => {
if (err) {
return callback(err, options);
}
const reportFile = path.join(releaseDir, "report.json");
options.files = files;
return fs.exists(reportFile, (exists) => {
if (!exists) {
return callback("ReportFileNotFound", options);
}
return fs.readFile(reportFile, (readErr, dataBuffer) => {
if (readErr) {
return callback(readErr, options);
}
const data = dataBuffer.toString();
if (!data) {
return callback("ReportFileNotFound", options);
}
options.report = JSON.parse(data);
return callback(null, options);
});
});
});
};
exports.getStatusMessageFromRelease = (app, options, callback) => {
const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
const reportFile = path.join(releaseDir, "/report.json");
options.attemptsGetReport = (options.attemptsGetReport || 0) + 1;
fs.exists(reportFile, (exists) => {
if (!exists) {
return setTimeout(() => fs.exists(releaseDir, (dirExists) => {
if (!dirExists) {
return callback("Release directory not found. Probably repository hooks are not configured");
}
if (options.attemptsGetReport > 100) {
return callback("Report file not found");
}
// Maybe it is building right now
return setTimeout(() => exports.getStatusMessageFromRelease(app, options, callback), 10000);
}), 2000);
}
return setTimeout(() => fs.readFile(reportFile, (err, dataBuffer) => {
if (err) {
return callback(err);
}
const data = dataBuffer.toString();
if (!data) {
return callback("Report file not found");
}
const report = JSON.parse(data);
if (report.result === "MBSNotFound") {
return callback("mbs.json is not found");
}
if (report.result && ((report.result.errors || {}).$allMessages || []).length + ((report.result.warns || {}).$allMessages || []).length > 0) {
return callback(_.map(
(report.result.errors || {}).$allMessages || [], (message) => `ERR: ${message.message}`
).concat(_.map(
(report.result.warns || {}).$allMessages || [], (message) => `WARN: ${message.message}`
))
.join("\r\n"));
}
if (!report.result || report.err) {
return callback(`CRITICAL ERROR: ${report.err}`);
}
if ((report.result.infos.$allMessages || []).length > 0) {
return callback(null, report.result.infos.$allMessages[report.result.infos.$allMessages.length - 1].message);
}
return callback(null, "OK");
}), 1000);
});
};

@ -4,6 +4,8 @@ const path = require("path");
const fs = require("fs");
const glob = require("glob");
const reportProcessor = require("./report-processor");
const addBranchInfo = (app, options, callback) => {
const branchFile = path.join(app.get("releasepath"), options.owner, options.reponame, "$revs", `${options.rev}.branch`);
@ -71,48 +73,10 @@ const parseOptions = (app, options, callback) => {
return addRevInfo(app, result, callback);
};
const loadReport = (app, options, callback) => {
const releaseDir = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
glob("**", {
"cwd": releaseDir,
"mark": true
}, (err, files) => {
if (err) {
return callback(err, options);
}
const reportFile = path.join(releaseDir, "report.json");
options.files = files;
return fs.exists(reportFile, (exists) => {
if (!exists) {
return callback("ReportFileNotFound", options);
}
return fs.readFile(reportFile, (err, dataBuffer) => {
if (err) {
return callback(err, options);
}
const data = dataBuffer.toString();
if (!data) {
return callback("ReportFileNotFound", options);
}
options.report = JSON.parse(data);
return callback(null, options);
});
});
});
};
exports.getReport = (app, options, callback) => parseOptions(app, options, (err, result) => {
if (err) {
return callback(err, {});
}
return loadReport(app, result, callback);
return reportProcessor.loadReport(app, result, callback);
});

Loading…
Cancel
Save