From 4085799726eb3976d843d2bc7152e350e6cbe261 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 3 Feb 2017 17:04:36 +0300 Subject: [PATCH] Fixes + improvements --- BuildServer/lib/commenter.js | 3 ++- BuildServer/lib/report-processor.js | 34 ++++++++++++++++++++--------- BuildServer/lib/task-processor.js | 2 +- BuildServer/lib/tasks/zip.js | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/BuildServer/lib/commenter.js b/BuildServer/lib/commenter.js index 0bd871b..a51bb73 100644 --- a/BuildServer/lib/commenter.js +++ b/BuildServer/lib/commenter.js @@ -134,9 +134,10 @@ const checkPullRequest = (options, callback) => { exports.commentOnPullRequest = (options, callback) => { options.github = settings.createGithub(options.baseRepoOptions.owner); + options.headRepoOptions.onTenthAttempt = () => writeComment(options, "Waiting for build to finish..."); return checkPullRequest(options, (err, successMessage) => reportProcessor.getStatusMessageFromRelease(options.app, options.headRepoOptions, (err, successMessage) => { - const escapedErr = (err || "").substring(0, 64000).replace(/`/g, "` "); + const escapedErr = String(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!` : `Build OK\r\n\r\n${successMessage}`; diff --git a/BuildServer/lib/report-processor.js b/BuildServer/lib/report-processor.js index 14e5eae..e6b02c3 100644 --- a/BuildServer/lib/report-processor.js +++ b/BuildServer/lib/report-processor.js @@ -10,32 +10,41 @@ const _ = require("underscore"); const reportFilename = "report.json.gz"; const writeReport = (releaseDir, err, result, callback) => { - const readable = new streamBuffers.ReadableStreamBuffer(); + const data = JSON.stringify({ + "date": Date.now(), + err, + result + }); + + const readable = new streamBuffers.ReadableStreamBuffer({ + chunkSize: 1024 * 256, + frequency: 1 + }); const writeStream = fs.createWriteStream(path.join(releaseDir, reportFilename)); readable + .on("error", callback) .pipe(zlib.createGzip()) + .on("error", callback) .pipe(writeStream) .on("error", callback) .on("finish", () => { - writeStream.close(); + writeStream.end(); callback(); }); - readable.put(JSON.stringify({ - "date": Date.now(), - err, - result - })); + readable.put(data); readable.stop(); }; const readReport = (releaseDir, callback) => { - const writable = new streamBuffers.WritableStreamBuffer(); const readStream = fs.createReadStream(path.join(releaseDir, reportFilename)); + const writable = new streamBuffers.WritableStreamBuffer(); readStream + .on("error", callback) .pipe(zlib.createGunzip()) + .on("error", callback) .pipe(writable) .on("error", callback) .on("finish", () => { @@ -100,12 +109,17 @@ exports.getStatusMessageFromRelease = (app, options, callback) => { 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); + if ((options.attemptsGetReport % 10 === 0) && options.onTenthAttempt) { + options.onTenthAttempt(); + } + + return setTimeout(() => exports.getStatusMessageFromRelease(app, options, callback), 30000); }), 2000); } @@ -136,6 +150,6 @@ exports.getStatusMessageFromRelease = (app, options, callback) => { } return callback(null, "OK"); - }), 1000); + }), 5000); }); }; diff --git a/BuildServer/lib/task-processor.js b/BuildServer/lib/task-processor.js index fa6a84b..3be5157 100644 --- a/BuildServer/lib/task-processor.js +++ b/BuildServer/lib/task-processor.js @@ -17,7 +17,7 @@ const TaskProcessor = function (task, outerProcessor, callback) { return `${task.name}/${prefix}`; } - return (task.name || "") + (prefix || ""); + return String(task.name || "") + String(prefix || ""); }; const onError = (message, prefix) => { errors.push(message); diff --git a/BuildServer/lib/tasks/zip.js b/BuildServer/lib/tasks/zip.js index 49d8eaa..64c6c9e 100644 --- a/BuildServer/lib/tasks/zip.js +++ b/BuildServer/lib/tasks/zip.js @@ -6,7 +6,7 @@ const Archiver = require("archiver"); module.exports = (params, processor) => ({ "process": () => { - const sourceDirectoryPath = path.normalize(path.join(processor.context.exported, params.directory || "")); + const sourceDirectoryPath = path.normalize(path.join(processor.context.exported, String(params.directory || ""))); const targetArchivePath = path.normalize(path.join(processor.context.release, params.archive)); processor.onInfo(`Compressing "${params.directory}" to "${params.archive}"`);