Code style improvements

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 7 years ago
parent 1416f83246
commit 6a8bde1c1f
  1. 75
      BuildServer/app.js
  2. 177
      BuildServer/lib/builder.js
  3. 85
      BuildServer/lib/commenter.js
  4. 102
      BuildServer/lib/git/copy.js
  5. 29
      BuildServer/lib/git/loader.js
  6. 6
      BuildServer/lib/mail-sender.js
  7. 62
      BuildServer/lib/status-processor.js
  8. 63
      BuildServer/lib/task-processor.js
  9. 25
      BuildServer/lib/tasks/cleanupafterdotnetbuild.js
  10. 11
      BuildServer/lib/tasks/conditional.js
  11. 14
      BuildServer/lib/tasks/copy.js
  12. 25
      BuildServer/lib/tasks/copyglob.js
  13. 22
      BuildServer/lib/tasks/cssnano.js
  14. 25
      BuildServer/lib/tasks/cssnanoall.js
  15. 34
      BuildServer/lib/tasks/deletefromcode.js
  16. 14
      BuildServer/lib/tasks/dotnetbuild.js
  17. 18
      BuildServer/lib/tasks/dotnetbuildandtest.js
  18. 39
      BuildServer/lib/tasks/dotnetbuilderwrapper.js
  19. 36
      BuildServer/lib/tasks/dotnetbuildwithoutcleanup.js
  20. 49
      BuildServer/lib/tasks/dotnetcheckstyle.js
  21. 42
      BuildServer/lib/tasks/dotnetcompile.js
  22. 41
      BuildServer/lib/tasks/dotnetnugetpack.js
  23. 46
      BuildServer/lib/tasks/dotnetnugetprocess.js
  24. 40
      BuildServer/lib/tasks/dotnetnugetpush.js
  25. 11
      BuildServer/lib/tasks/dotnetnugetpushonly.js
  26. 17
      BuildServer/lib/tasks/dotnetnugetrestore.js
  27. 8
      BuildServer/lib/tasks/dotnetnunit.js
  28. 28
      BuildServer/lib/tasks/dotnetnunitall.js
  29. 63
      BuildServer/lib/tasks/dotnetpackwebapp.js
  30. 35
      BuildServer/lib/tasks/dotnetrewrite.js
  31. 2
      BuildServer/lib/tasks/echo.js
  32. 17
      BuildServer/lib/tasks/eslintbrowser.js
  33. 25
      BuildServer/lib/tasks/eslintbrowserall.js
  34. 4
      BuildServer/lib/tasks/noop.js
  35. 38
      BuildServer/lib/tasks/packform.js
  36. 6
      BuildServer/lib/tasks/parallel.js
  37. 9
      BuildServer/lib/tasks/sequential.js
  38. 13
      BuildServer/lib/tasks/uglifyjs.js
  39. 25
      BuildServer/lib/tasks/uglifyjsall.js
  40. 13
      BuildServer/lib/tasks/writefile.js
  41. 16
      BuildServer/lib/tasks/zip.js
  42. 16
      BuildServer/routes/artifact.js
  43. 12
      BuildServer/routes/index.js
  44. 17
      BuildServer/routes/manual.js
  45. 82
      BuildServer/routes/postreceive.js
  46. 48
      BuildServer/routes/release.js
  47. 50
      BuildServer/routes/status.js

@ -1,55 +1,56 @@
"use strict"; "use strict";
//const https = require('https'); const realFs = require("fs");
const realFs = require('fs'); const fs = require("graceful-fs");
const fs = require('graceful-fs');
fs.gracefulify(realFs); fs.gracefulify(realFs);
const express = require('express'); const express = require("express");
const routes = require('./routes'); const routes = require("./routes");
const http = require('http'); const http = require("http");
const path = require('path'); const path = require("path");
const serveFavicon = require('serve-favicon'); const serveFavicon = require("serve-favicon");
const morgan = require('morgan'); const morgan = require("morgan");
const bodyParser = require('body-parser'); const bodyParser = require("body-parser");
const methodOverride = require('method-override'); const methodOverride = require("method-override");
const serveStatic = require('serve-static'); const serveStatic = require("serve-static");
const errorhandler = require('errorhandler'); const errorhandler = require("errorhandler");
const settings = require("./settings");
const app = express(); const app = express();
// all environments // All environments
app.set('port', process.env.PORT || 3000); app.set("port", settings.port);
app.set('views', path.join(__dirname, 'views')); app.set("views", path.join(__dirname, "views"));
app.set('view engine', 'jade'); app.set("view engine", "jade");
app.set('gitpath', 'M:/g'); app.set("gitpath", settings.gitpath);
app.set('tmpcodepath', 'M:/c'); app.set("tmpcodepath", settings.tmpcodepath);
app.set('releasepath', 'M:/r'); app.set("releasepath", settings.releasepath);
app.use(serveFavicon(path.join(__dirname, 'public/images/favicon.png'))); app.use(serveFavicon(path.join(__dirname, "public/images/favicon.png")));
app.use(morgan('dev')); app.use(morgan("dev"));
app.use(bodyParser.json({ limit: '10mb' })); app.use(bodyParser.json({ "limit": "10mb" }));
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.urlencoded({ "extended": false }));
app.use(methodOverride()); app.use(methodOverride());
app.use(serveStatic(path.join(__dirname, 'public'))); app.use(serveStatic(path.join(__dirname, "public")));
// development only if (app.get("env") === "development") {
if ('development' === app.get('env')) {
app.use(errorhandler()); app.use(errorhandler());
} }
app.route('/').get(routes.index); app.route("/").get(routes.index);
app.route('/github/postreceive') app.route("/github/postreceive")
.post(routes.postreceive) .post(routes.postreceive)
.get((req, res) => res.send("Only automated POST requests are allowed for postreceive route")); .get((req, res) => res.send("Only automated POST requests are allowed for postreceive route"));
app.route('/manual') app.route("/manual")
.get(routes.manual.get) .get(routes.manual.get)
.post(routes.manual.post); .post(routes.manual.post);
app.route('/status/:owner/:reponame/:branch/:rev?').get(routes.status.page); app.route("/status/:owner/:reponame/:branch/:rev?").get(routes.status.page);
app.route('/pos-github.payonline.ru/*').get(routes.status.pageFromGithub); app.route("/pos-github.payonline.ru/*").get(routes.status.pageFromGithub);
app.route('/status.svg').get(routes.status.image); app.route("/status.svg").get(routes.status.image);
app.route('/release/:owner/:reponame/:branch/:rev').get(routes.release); app.route("/release/:owner/:reponame/:branch/:rev").get(routes.release);
app.route('/artifact/:owner/:reponame/:branch/:rev/*').get(routes.artifact); app.route("/artifact/:owner/:reponame/:branch/:rev/*").get(routes.artifact);
http.createServer(app).listen(app.get('port'), () => console.log('Express server listening on port ' + app.get('port'))); http.createServer(app).listen(app.get("port"), () => console.log(`Express server listening on port ${app.get("port")}`));

@ -1,31 +1,34 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const fse = require('fs-extra'); const fs = require("fs");
const async = require('async'); const fse = require("fs-extra");
const gitLoader = require('./git/loader'); const async = require("async");
const processor = require('./task-processor'); const gitLoader = require("./git/loader");
const mailSender = require('./mail-sender'); const processor = require("./task-processor");
const settings = require('../settings'); const mailSender = require("./mail-sender");
const settings = require("../settings");
//const codePostfix = "/code";
const codePostfix = ""; const codePostfix = "";
const notifyStatus = (options, callback) => { const notifyStatus = (options, callback) => {
const status = { const status = {
owner: options.owner, "description": String(options.description || "").substr(0, 140),
repo: options.reponame, "owner": options.owner,
sha: options.hash, "repo": options.reponame,
state: options.state, "sha": options.hash,
target_url: settings.siteRoot + "status/" + options.owner + "/" + options.reponame + "/" + options.hash, "state": options.state,
description: ((options.description || "") + "").substr(0, 140) "target_url": `${settings.siteRoot}status/${options.owner}/${options.reponame}/${options.hash}`
}; };
settings.createGithub(options.owner).repos.createStatus(status, (err, result) => {
settings.createGithub(options.owner).repos.createStatus(status, (err) => {
if (err) { if (err) {
console.log("Error while creating status: " + err); console.log(`Error while creating status: ${err}`);
console.log(status); console.log(status);
return callback(err); return callback(err);
} }
return callback(); return callback();
}); });
}; };
@ -37,59 +40,76 @@ const build = (options, callback) => {
const rev = options.rev; const rev = options.rev;
const branch = options.branch; const branch = options.branch;
const skipGitLoader = options.skipGitLoader; const skipGitLoader = options.skipGitLoader;
const local = options.app.get('gitpath') + "/r/"; const local = path.join(options.app.get("gitpath"), "r");
const tmp = options.app.get('tmpcodepath') + "/" + rev.substr(0, 15); const tmp = path.join(options.app.get("tmpcodepath"), rev.substr(0, 15));
const exported = tmp + codePostfix; const exported = tmp + codePostfix;
const release = options.app.get('releasepath') + "/" + owner + "/" + reponame + "/" + branch + "/" + rev; const release = path.join(options.app.get("releasepath"), owner, reponame, branch, rev);
const statusQueue = async.queue((task, callback) => task(callback), 1); const statusQueue = async.queue((task, callback) => task(callback), 1);
const actualGitLoader = skipGitLoader ? (options, callback) => process.nextTick(callback) : gitLoader; const actualGitLoader = skipGitLoader
? (options, callback) => process.nextTick(callback)
: gitLoader;
const date = new Date(); const date = new Date();
const versionInfo = date.getFullYear() + "." + const versionMajor = date.getFullYear();
(date.getMonth() + 1) + "." + const versionMinor = date.getMonth() + 1;
date.getDate() + "." + const versionBuild = date.getDate();
(date.getHours() * 100 + date.getMinutes()) + "; " + const versionRev = (date.getHours() * 100) + date.getMinutes();
"built from " + rev + "; " + const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`;
"repository: " + owner + "/" + reponame + "; " + const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`;
"branch: " + branch;
statusQueue.push((callback) => notifyStatus({ statusQueue.push((callback) => notifyStatus({
state: "pending", "description": "Preparing to build...",
description: "Preparing to build...", "hash": rev,
owner: owner, owner,
reponame: reponame, reponame,
hash: rev "state": "pending"
}, callback)); }, callback));
fse.mkdirsSync(release); fse.mkdirsSync(release);
fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/" + branch + "/latest.id", rev); fs.writeFileSync(path.join(options.app.get("releasepath"), owner, reponame, branch, "latest.id"), rev);
fse.mkdirsSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs"); fse.mkdirsSync(path.join(options.app.get("releasepath"), owner, reponame, "$revs"));
fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs/" + rev + ".branch", branch); fs.writeFileSync(path.join(options.app.get("releasepath"), owner, reponame, "$revs", `${rev}.branch`), branch);
const done = (err, result) => { const done = (err, result) => {
const errorMessage = result && result.errors ? ((result.errors.$allMessages || [])[0] || {}).message : err; const errorMessage = result && result.errors
const warnMessage = result && result.warns ? ((result.warns.$allMessages || [])[0] || {}).message : err; ? ((result.errors.$allMessages || [])[0] || {}).message
const infoMessage = result && result.infos ? ((result.infos.$allMessages || []).slice(-1)[0] || {}).message : err; : err;
const warnMessage = result && result.warns
fs.writeFile(release + "/report.json", JSON.stringify({date: Date.now(), err: err, result: result}), (writeErr) => { ? ((result.warns.$allMessages || [])[0] || {}).message
: err;
const infoMessage = result && result.infos
? ((result.infos.$allMessages || []).slice(-1)[0] || {}).message
: err;
fs.writeFile(path.join(release, "report.json"), JSON.stringify({
"date": Date.now(),
err,
result
}), (writeErr) => {
statusQueue.push((callback) => async.parallel([ statusQueue.push((callback) => async.parallel([
(callback) => notifyStatus({ (callback) => notifyStatus({
state: err ? "error" : "success", "description": errorMessage || warnMessage || infoMessage || "Success",
description: errorMessage || warnMessage || infoMessage || "Success", "hash": rev,
owner: owner, owner,
reponame: reponame, reponame,
hash: rev "state": err
? "error"
: "success"
}, callback), }, callback),
(callback) => mailSender.send({ (callback) => mailSender.send({
from: settings.smtp.sender, "from": settings.smtp.sender,
to: settings.smtp.receiver, "headers": { "X-Laziness-level": 1000 },
subject: (err ? "Build failed for " : "Successfully built ") + owner + "/" + reponame + "/" + branch, "subject": `${err ? "Build failed for" : "Successfully built"} ${owner}/${reponame}/${branch}`,
headers: { "text": `Build status URL: ${settings.siteRoot}status/${owner}/${reponame}/${rev}\r\n\r\n`
'X-Laziness-level': 1000 + (
}, err
text: ("Build status URL: " + settings.siteRoot + "status/" + owner + "/" + reponame + "/" + rev + "\r\n\r\n") + ? `Error message: ${err}\r\n\r\n`
(err ? ("Error message: " + err + "\r\n\r\n") : "") + : "")
((!result || !result.messages || !result.messages.$allMessages) ? JSON.stringify(result, null, 4) : result.messages.$allMessages.map(msg => msg.prefix + "\t" + msg.message).join("\r\n")) + (
(!result || !result.messages || !result.messages.$allMessages)
? JSON.stringify(result, null, 4)
: result.messages.$allMessages.map((msg) => `${msg.prefix}\t${msg.message}`).join("\r\n")),
"to": settings.smtp.receiver
}, callback), }, callback),
(callback) => { (callback) => {
if (err) { if (err) {
@ -103,48 +123,55 @@ const build = (options, callback) => {
if (writeErr) { if (writeErr) {
return callback(writeErr); return callback(writeErr);
} }
return callback(err, result); return callback(err, result);
}); });
}; };
actualGitLoader({ actualGitLoader({
remote: url + ".git", branch,
local: local, exported,
branch: branch, "hash": rev,
hash: rev, local,
exported: tmp + codePostfix "remote": `${url}.git`
}, (err) => { }, (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
return done("Git fetch error: " + err);
return done(`Git fetch error: ${err}`);
} }
console.log("Done loading from git"); console.log("Done loading from git");
fs.exists(exported + "/mbs.json", (exists) => {
return fs.exists(path.join(exported, "mbs.json"), (exists) => {
if (!exists) { if (!exists) {
return done(null, "MBSNotFound"); return done(null, "MBSNotFound");
} }
fs.readFile(exported + "/mbs.json", (err, data) => {
return fs.readFile(path.join(exported, "mbs.json"), (err, data) => {
if (err) { if (err) {
return done(err, "MBSUnableToRead"); return done(err, "MBSUnableToRead");
} }
let task; let task = null;
try { try {
task = JSON.parse(data); task = JSON.parse(data);
} catch(ex) { } catch (ex) {
console.log("Malformed data: " + data); console.log(`Malformed data: ${data}`);
return done(ex, "MBSMalformed"); return done(ex, "MBSMalformed");
} }
processor.processTask(task, { return processor.processTask(task, {
owner: owner, branch,
reponame: reponame, exported,
branch: branch, owner,
rev: rev, release,
tmp: tmp, reponame,
exported: exported, rev,
release: release, tmp,
versionInfo: versionInfo versionInfo
}, (err, result) => { }, (err, result) => {
if (err) { if (err) {
return done(err, result); return done(err, result);

@ -1,5 +1,6 @@
"use strict"; "use strict";
const path = require("path");
const fs = require("fs"); const fs = require("fs");
const _ = require("underscore"); const _ = require("underscore");
const settings = require("../settings"); const settings = require("../settings");
@ -9,10 +10,10 @@ const versionNamePattern = /^v\d+(\.\d+)*$/;
const masterNamePattern = /^master$/; const masterNamePattern = /^master$/;
const writeComment = (options, message, callback) => options.github.issues.createComment({ const writeComment = (options, message, callback) => options.github.issues.createComment({
owner: options.baseRepoOptions.owner, "body": message,
repo: options.baseRepoOptions.reponame, "number": options.number,
number: options.number, "owner": options.baseRepoOptions.owner,
body: message "repo": options.baseRepoOptions.reponame
}, callback); }, callback);
const closePullRequest = (options, message, callback) => writeComment(options, message, (err) => { const closePullRequest = (options, message, callback) => writeComment(options, message, (err) => {
@ -21,43 +22,43 @@ const closePullRequest = (options, message, callback) => writeComment(options, m
} }
return options.github.issues.edit({ return options.github.issues.edit({
owner: options.baseRepoOptions.owner, "number": options.number,
repo: options.baseRepoOptions.reponame, "owner": options.baseRepoOptions.owner,
number: options.number, "repo": options.baseRepoOptions.reponame,
state: "closed" "state": "closed"
}, callback); }, callback);
}); });
const checkHasIssue = (options, issueNumber, callback) => options.github.issues.get({ const checkHasIssue = (options, issueNumber, callback) => options.github.issues.get({
owner: options.baseRepoOptions.owner, "number": issueNumber,
repo: options.baseRepoOptions.reponame, "owner": options.baseRepoOptions.owner,
number: issueNumber "repo": options.baseRepoOptions.reponame
}, (err, result) => { }, (err, result) => {
if (err && err.code !== 404) { if (err && err.code !== 404) {
return callback(err); return callback(err);
} }
if (err || result.number.toString() !== issueNumber) { if (err || result.number.toString() !== issueNumber) {
return callback(undefined, false); return callback(null, false);
} }
if (result.pull_request && result.pull_request.url) { if (result.pull_request && result.pull_request.url) {
return callback(undefined, false); return callback(null, false);
} }
return callback(undefined, true, result.title); return callback(null, true, result.title);
}); });
const checkHasReleases = (options, callback) => options.github.repos.getReleases({ const checkHasReleases = (options, callback) => options.github.repos.getReleases({
owner: options.baseRepoOptions.owner, "owner": options.baseRepoOptions.owner,
repo: options.baseRepoOptions.reponame, "per_page": 1,
per_page: 1 "repo": options.baseRepoOptions.reponame
}, (err, result) => { }, (err, result) => {
if (err) { if (err) {
return callback(err); return callback(err);
} }
return callback(undefined, result && result.length); return callback(null, result && result.length);
}); });
const checkPullRequest = (options, callback) => { const checkPullRequest = (options, callback) => {
@ -83,7 +84,7 @@ const checkPullRequest = (options, callback) => {
} }
if (options.action === "opened") { if (options.action === "opened") {
return writeComment(options, "Switching master branch to " + head.branchname + " release", callback); return writeComment(options, `Switching master branch to ${head.branchname} release`, callback);
} }
return process.nextTick(callback); return process.nextTick(callback);
@ -91,24 +92,26 @@ const checkPullRequest = (options, callback) => {
} }
if (!featureNamePattern.test(head.branchname)) { if (!featureNamePattern.test(head.branchname)) {
return closePullRequest(options, "Only merging from feature branch is allowed (pattern: `" + featureNamePattern.toString() + "`)", callback); return closePullRequest(options, `Only merging from feature branch is allowed (pattern: \`${featureNamePattern}\`)`, callback);
} }
if (!versionNamePattern.test(base.branchname) && !masterNamePattern.test(base.branchname)) { if (!versionNamePattern.test(base.branchname) && !masterNamePattern.test(base.branchname)) {
return closePullRequest(options, "Only merging to master or version branch is allowed; merging to '" + base.branchname + "' is not supported", callback); return closePullRequest(options, `Only merging to master or version branch is allowed; merging to '${base.branchname}' is not supported`, callback);
} }
const issueNumber = featureNamePattern.exec(head.branchname)[1]; const issueNumber = featureNamePattern.exec(head.branchname)[1];
return checkHasIssue(options, issueNumber, (err, hasIssue, issueTitle) => { return checkHasIssue(options, issueNumber, (err, hasIssue, issueTitle) => {
if (err) { if (err) {
return writeComment(options, "Unable to check for issue:\r\n\r\n" + err.message, callback); return writeComment(options, `Unable to check for issue:\r\n\r\n${err.message}`, callback);
} }
if (!hasIssue) { if (!hasIssue) {
return closePullRequest(options, "Unable to find issue #" + issueNumber, callback); return closePullRequest(options, `Unable to find issue #${issueNumber}`, callback);
} }
const shouldHaveReleases = versionNamePattern.test(base.branchname); const shouldHaveReleases = versionNamePattern.test(base.branchname);
return checkHasReleases(options, (err, hasReleases) => { return checkHasReleases(options, (err, hasReleases) => {
if (err) { if (err) {
return writeComment(options, "Unable to check for releases", callback); return writeComment(options, "Unable to check for releases", callback);
@ -123,7 +126,7 @@ const checkPullRequest = (options, callback) => {
} }
if (options.action === "opened") { if (options.action === "opened") {
return writeComment(options, "Merging feature #" + issueNumber + " (" + issueTitle + ") to " + base.branchname + (shouldHaveReleases ? " release" : ""), callback); return writeComment(options, `Merging feature #${issueNumber} (${issueTitle}) to ${base.branchname}${shouldHaveReleases ? " release" : ""}`, callback);
} }
return process.nextTick(callback); return process.nextTick(callback);
@ -132,8 +135,8 @@ const checkPullRequest = (options, callback) => {
}; };
const getStatusMessageFromRelease = (app, options, callback) => { const getStatusMessageFromRelease = (app, options, callback) => {
const releaseDir = 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);
const reportFile = releaseDir + "/report.json"; const reportFile = path.join(releaseDir, "/report.json");
options.attemptsGetReport = (options.attemptsGetReport || 0) + 1; options.attemptsGetReport = (options.attemptsGetReport || 0) + 1;
@ -147,7 +150,7 @@ const getStatusMessageFromRelease = (app, options, callback) => {
return callback("Report file not found"); return callback("Report file not found");
} }
//maybe it is building right now // Maybe it is building right now
return setTimeout(() => getStatusMessageFromRelease(app, options, callback), 10000); return setTimeout(() => getStatusMessageFromRelease(app, options, callback), 10000);
}), 2000); }), 2000);
} }
@ -156,10 +159,13 @@ const getStatusMessageFromRelease = (app, options, callback) => {
if (err) { if (err) {
return callback(err); return callback(err);
} }
const data = dataBuffer.toString(); const data = dataBuffer.toString();
if (!data) { if (!data) {
return callback("Report file not found"); return callback("Report file not found");
} }
const report = JSON.parse(data); const report = JSON.parse(data);
if (report.result === "MBSNotFound") { if (report.result === "MBSNotFound") {
@ -167,27 +173,34 @@ const getStatusMessageFromRelease = (app, options, callback) => {
} }
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}`
).concat(_.map( ).concat(_.map(
(report.result.warns || {}).$allMessages || [], (message) => "WARN: " + message.message (report.result.warns || {}).$allMessages || [], (message) => `WARN: ${message.message}`
)).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(undefined, 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);
} }
return callback(undefined, "OK");
return callback(null, "OK");
}), 1000); }), 1000);
}); });
}; };
exports.commentOnPullRequest = (options, callback) => { exports.commentOnPullRequest = (options, callback) => {
options.github = settings.createGithub(options.baseRepoOptions.owner); options.github = settings.createGithub(options.baseRepoOptions.owner);
return checkPullRequest(options, (err, successMessage) => getStatusMessageFromRelease(options.app, options.headRepoOptions, (err, successMessage) => { return checkPullRequest(options, (err, successMessage) => getStatusMessageFromRelease(options.app, options.headRepoOptions, (err, successMessage) => {
const message = err ? ("Was not built:\r\n\r\n```\r\n" + err.substring(0, 64000).replace(/```/g, "` ` `") + "\r\n```\r\n\r\nDO NOT MERGE!") : ("Build OK\r\n\r\n" + successMessage); const escapedErr = err.substring(0, 64000).replace(/`/g, "` ");
const statusUrlMessage = "Build status URL: " + settings.siteRoot + "status/" + options.headRepoOptions.owner + "/" + options.headRepoOptions.reponame + "/" + options.headRepoOptions.rev + "\r\n\r\n"; const message = err
return writeComment(options, message + "\r\n\r\n" + statusUrlMessage, callback); ? `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}`;
const statusUrlMessage = `Build status URL: ${settings.siteRoot}status/${options.headRepoOptions.owner}/${options.headRepoOptions.reponame}/${options.headRepoOptions.rev}\r\n\r\n`;
return writeComment(options, `${message}\r\n\r\n${statusUrlMessage}`, callback);
})); }));
}; };

@ -1,69 +1,82 @@
"use strict"; "use strict";
const EventEmitter = require('events').EventEmitter; const EventEmitter = require("events").EventEmitter;
const path = require('path'); const path = require("path");
const fs = require('fs'); const fs = require("fs");
const async = require('async'); const async = require("async");
const Copier = require('recursive-tree-copy').Copier; const Copier = require("recursive-tree-copy").Copier;
const gitToFsCopier = new Copier({ const gitToFsCopier = new Copier({
concurrency: 4, "concurrency": 4,
walkSourceTree: (tree) => { "copyLeaf": (entry, targetDir, callback) => {
const targetPath = path.join(targetDir, entry.name());
entry.getBlob((err, blob) => {
if (err) {
return callback(err);
}
return fs.writeFile(targetPath, blob.content(), callback);
});
},
"createTargetTree": (tree, targetDir, callback) => {
const targetSubdir = path.join(targetDir, tree.name);
fs.mkdir(targetSubdir, (err) => {
// Workaround for broken trees
if (err && err.code !== "EEXIST") {
return callback(err);
}
return callback(null, targetSubdir);
});
},
"finalizeTargetTree": (targetSubdir, callback) => callback(),
"walkSourceTree": (tree) => {
const emitter = new EventEmitter(); const emitter = new EventEmitter();
process.nextTick(() => { process.nextTick(() => {
let entries; let entries = null;
try { try {
entries = tree.gitTree.entries(); entries = tree.gitTree.entries();
} catch(err) { } catch (err) {
return emitter.emit('error', err); return emitter.emit("error", err);
} }
async.parallel(entries.map((entry) => (callback) => { return async.parallel(entries.map((entry) => (callback) => {
if (entry.isTree()) { if (entry.isTree()) {
entry.getTree((err, subTree) => { return entry.getTree((err, subTree) => {
if (err) { if (err) {
return callback(err); return callback(err);
} }
emitter.emit('tree', { gitTree: subTree, name: entry.name() }); emitter.emit("tree", {
callback(); "gitTree": subTree,
"name": entry.name()
});
return callback();
}); });
} else if (entry.isFile()) {
emitter.emit('leaf', entry);
callback();
} else {
callback();
} }
if (entry.isFile()) {
emitter.emit("leaf", entry);
return callback();
}
return callback();
}), (err) => { }), (err) => {
if (err) { if (err) {
return emitter.emit('error', err); return emitter.emit("error", err);
} }
return emitter.emit('done'); return emitter.emit("done");
}); });
}); });
return emitter;
},
createTargetTree: (tree, targetDir, callback) => {
const targetSubdir = path.join(targetDir, tree.name);
fs.mkdir(targetSubdir, (err) => {
if (err && err.code !== 'EEXIST' /* workaround for broken trees */) {
return callback(err);
}
callback(undefined, targetSubdir);
});
},
finalizeTargetTree: (targetSubdir, callback) => callback(),
copyLeaf: (entry, targetDir, callback) => {
const targetPath = path.join(targetDir, entry.name());
entry.getBlob((err, blob) => {
if (err) {
return callback(err);
}
fs.writeFile(targetPath, blob.content(), callback); return emitter;
});
} }
}); });
@ -72,5 +85,8 @@ exports.gitToFs = (commit, exportDir, callback) => commit.getTree((err, tree) =>
return callback(err); return callback(err);
} }
gitToFsCopier.copy({ gitTree: tree, name: "." }, exportDir, callback); return gitToFsCopier.copy({
"gitTree": tree,
"name": "."
}, exportDir, callback);
}); });

@ -1,18 +1,16 @@
"use strict"; "use strict";
const nodegit = require('nodegit'); const nodegit = require("nodegit");
const fse = require('fs-extra'); const fse = require("fs-extra");
const gitToFs = require('./copy').gitToFs; const gitToFs = require("./copy").gitToFs;
const mkdirs = (path) => { const mkdirs = (path) => {
/*jslint stupid: true */ fse.mkdirsSync(path); // eslint-disable-line no-sync
fse.mkdirsSync(path);
}; };
const removedirs = (path) => { const removedirs = (path) => {
/*jslint stupid: true */ fse.removeSync(path); // eslint-disable-line no-sync
fse.removeSync(path);
}; };
/* /* Example:
options = { options = {
"remote": "https://github.com/visionmedia/express.git", "remote": "https://github.com/visionmedia/express.git",
"local": "D:\\data\\repositories\\visionmedia\\express.git\\", "local": "D:\\data\\repositories\\visionmedia\\express.git\\",
@ -20,21 +18,21 @@ options = {
"hash": "82e15cf321fccf3215068814d1ea1aeb3581ddb3", "hash": "82e15cf321fccf3215068814d1ea1aeb3581ddb3",
"exported": "D:\\data\\exportedsource\\visionmedia\\express\\82e15cf321fccf3215068814d1ea1aeb3581ddb3\\", "exported": "D:\\data\\exportedsource\\visionmedia\\express\\82e15cf321fccf3215068814d1ea1aeb3581ddb3\\",
} }
*/ */
module.exports = (options, globalCallback) => { module.exports = (options, globalCallback) => {
let url = options.remote; let url = options.remote;
const path = options.local + "/" + options.hash; const path = `${options.local}/${options.hash}`;
const exported = options.exported; const exported = options.exported;
removedirs(path); removedirs(path);
mkdirs(path); mkdirs(path);
if (url.substr(0, 8) === "https://") { if (url.substr(0, 8) === "https://") {
url = "git://" + url.substr(8); url = `git://${url.substr(8)}`;
} }
console.log("Cloning %s to %s", url, path); console.log(`Cloning ${url} to ${path}`);
nodegit.Repository.init(path, 1) nodegit.Repository.init(path, 1)
.catch(globalCallback) .catch(globalCallback)
@ -44,12 +42,12 @@ module.exports = (options, globalCallback) => {
.catch(globalCallback) .catch(globalCallback)
.then((number) => { .then((number) => {
if (number) { if (number) {
return globalCallback("Failed to fetch commit: error number " + number); return globalCallback(`Failed to fetch commit: error number ${number}`);
} }
console.log("Cloned %s to %s", url, path); console.log(`Cloned ${url} to ${path}`);
repo.getCommit(options.hash) return repo.getCommit(options.hash)
.catch(globalCallback) .catch(globalCallback)
.then((commit) => { .then((commit) => {
removedirs(exported); removedirs(exported);
@ -57,6 +55,7 @@ module.exports = (options, globalCallback) => {
gitToFs(commit, exported, (err, result) => { gitToFs(commit, exported, (err, result) => {
repo.free(); repo.free();
return globalCallback(err, result); return globalCallback(err, result);
}); });
}); });

@ -1,7 +1,7 @@
"use strict"; "use strict";
const nodemailer = require('nodemailer'); const nodemailer = require("nodemailer");
const settings = require('../settings'); const settings = require("../settings");
exports.send = (message, callback) => { exports.send = (message, callback) => {
return process.nextTick(callback); return process.nextTick(callback);
@ -12,4 +12,4 @@ exports.send = (message, callback) => {
callback(err, result); callback(err, result);
}); });
*/ */
}; };

@ -1,88 +1,108 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const glob = require('glob'); const fs = require("fs");
const glob = require("glob");
const addBranchInfo = (app, options, callback) => { const addBranchInfo = (app, options, callback) => {
const branchFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/$revs/" + options.rev + ".branch"; const branchFile = path.join(app.get("releasepath"), options.owner, options.reponame, "$revs", `${options.rev}.branch`);
fs.exists(branchFile, (exists) => { fs.exists(branchFile, (exists) => {
if (!exists) { if (!exists) {
return callback("BranchFileNotFound", options); return callback("BranchFileNotFound", options);
} }
fs.readFile(branchFile, (err, data) => {
return fs.readFile(branchFile, (err, data) => {
if (err) { if (err) {
return callback(err, options); return callback(err, options);
} }
options.branch = data.toString(); options.branch = data.toString();
options.branchName = options.branch.split("/").pop(); options.branchName = options.branch.split("/").pop();
return callback(null, options); return callback(null, options);
}); });
}); });
}; };
const addRevInfo = (app, options, callback) => { const addRevInfo = (app, options, callback) => {
const revFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/latest.id"; const revFile = path.join(app.get("releasepath"), options.owner, options.reponame, options.branch, "latest.id");
fs.exists(revFile, (exists) => { fs.exists(revFile, (exists) => {
if (!exists) { if (!exists) {
return callback("RevFileNotFound", options); return callback("RevFileNotFound", options);
} }
fs.readFile(revFile, (err, data) => {
return fs.readFile(revFile, (err, data) => {
if (err) { if (err) {
return callback(err, options); return callback(err, options);
} }
options.rev = data.toString(); options.rev = data.toString();
return callback(null, options); return callback(null, options);
}); });
}); });
}; };
const parseOptions = (app, options, callback) => { const parseOptions = (app, options, callback) => {
const result = {}; const result = {
"owner": options.owner,
result.owner = options.owner; "reponame": options.reponame
result.reponame = options.reponame; };
if (options.rev && !(/^[\da-f]{40}$/i).test(options.rev)) { if (options.rev && !(/^[\da-f]{40}$/i).test(options.rev)) {
return callback("Wrong rev format: " + options.rev, options); return callback(`Wrong rev format: ${options.rev}`, options);
} }
if (options.rev) { if (options.rev) {
result.rev = options.rev; result.rev = options.rev;
return addBranchInfo(app, result, callback); return addBranchInfo(app, result, callback);
} else if (/^[\da-f]{40}$/i.test(options.branchName)) { }
if (/^[\da-f]{40}$/i.test(options.branchName)) {
result.rev = options.branchName; result.rev = options.branchName;
return addBranchInfo(app, result, callback); return addBranchInfo(app, result, callback);
} else {
result.branchName = options.branchName || "master";
result.branch = "refs/heads/" + result.branchName;
return addRevInfo(app, result, callback);
} }
result.branchName = options.branchName || "master";
result.branch = `refs/heads/${result.branchName}`;
return addRevInfo(app, result, callback);
}; };
const loadReport = (app, options, callback) => { const loadReport = (app, options, callback) => {
const releaseDir = 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);
glob("**", {cwd: releaseDir, mark: true}, (err, files) => { glob("**", {
"cwd": releaseDir,
"mark": true
}, (err, files) => {
if (err) { if (err) {
return callback(err, options); return callback(err, options);
} }
const reportFile = releaseDir + "/report.json"; const reportFile = path.join(releaseDir, "report.json");
options.files = files; options.files = files;
fs.exists(reportFile, (exists) => {
return fs.exists(reportFile, (exists) => {
if (!exists) { if (!exists) {
return callback("ReportFileNotFound", options); return callback("ReportFileNotFound", options);
} }
fs.readFile(reportFile, (err, dataBuffer) => { return fs.readFile(reportFile, (err, dataBuffer) => {
if (err) { if (err) {
return callback(err, options); return callback(err, options);
} }
const data = dataBuffer.toString(); const data = dataBuffer.toString();
if (!data) { if (!data) {
return callback("ReportFileNotFound", options); return callback("ReportFileNotFound", options);
} }
options.report = JSON.parse(data); options.report = JSON.parse(data);
return callback(null, options); return callback(null, options);
}); });
}); });

@ -1,16 +1,22 @@
"use strict"; "use strict";
//TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here. // TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here.
const TaskProcessor = function (task, outerProcessor, callback) { const TaskProcessor = function (task, outerProcessor, callback) {
if (!this) { if (!this) {
return new TaskProcessor(task); return new TaskProcessor(task);
} }
const self = this; const that = this;
let taskWorker = undefined; let taskWorker = null;
const errors = []; const errors = [];
const process = () => taskWorker.process(); const process = () => taskWorker.process();
const getOuterPrefix = (prefix) => (task.name && prefix) ? (task.name + "/" + prefix) : (task.name || "") + (prefix || ""); const getOuterPrefix = (prefix) => {
if (task.name && prefix) {
return `${task.name}/${prefix}`;
}
return (task.name || "") + (prefix || "");
};
const onError = (message, prefix) => { const onError = (message, prefix) => {
errors.push(message); errors.push(message);
outerProcessor.onError(message, getOuterPrefix(prefix)); outerProcessor.onError(message, getOuterPrefix(prefix));
@ -18,21 +24,25 @@ const TaskProcessor = function (task, outerProcessor, callback) {
const onWarn = (message, prefix) => outerProcessor.onWarn(message, getOuterPrefix(prefix)); const onWarn = (message, prefix) => outerProcessor.onWarn(message, getOuterPrefix(prefix));
const onInfo = (message, prefix) => outerProcessor.onInfo(message, getOuterPrefix(prefix)); const onInfo = (message, prefix) => outerProcessor.onInfo(message, getOuterPrefix(prefix));
const processTask = (innerTask, innerCallback) => { const processTask = (innerTask, innerCallback) => {
const innerProcessor = new TaskProcessor(innerTask, self, innerCallback); const innerProcessor = new TaskProcessor(innerTask, that, innerCallback);
innerProcessor.process(); innerProcessor.process();
}; };
const done = () => callback(errors.join("\r\n")); const done = () => callback(errors.join("\r\n"));
self.process = process; that.process = process;
self.onError = onError; that.onError = onError;
self.onWarn = onWarn; that.onWarn = onWarn;
self.onInfo = onInfo; that.onInfo = onInfo;
self.processTask = processTask; that.processTask = processTask;
self.done = done; that.done = done;
self.context = outerProcessor.context; that.context = outerProcessor.context;
const taskImpl = require('./tasks/' + task.type.match(/[\w\-]/g).join("")); const taskImpl = require(`./tasks/${task.type.match(/[\w\-]/g).join("")}`);
taskWorker = taskImpl(task.params || {}, self);
taskWorker = taskImpl(task.params || {}, that);
return this;
}; };
exports.processTask = (task, context, callback) => { exports.processTask = (task, context, callback) => {
@ -46,14 +56,17 @@ exports.processTask = (task, context, callback) => {
let innerList = list; let innerList = list;
parts.forEach((part) => { parts.forEach((part) => {
innerList = (innerList[part] = innerList[part] || {}); innerList = innerList[part] = innerList[part] || {};
}); });
innerList.$messages = innerList.$messages || []; innerList.$messages = innerList.$messages || [];
innerList.$messages.push(message); innerList.$messages.push(message);
list.$allMessages = list.$allMessages || []; list.$allMessages = list.$allMessages || [];
list.$allMessages.push({ prefix: prefix, message: message }); list.$allMessages.push({
message,
prefix
});
}; };
return (message, prefix) => { return (message, prefix) => {
@ -62,15 +75,15 @@ exports.processTask = (task, context, callback) => {
}; };
}; };
const processor = new TaskProcessor(task, { const processor = new TaskProcessor(task, {
onError: messageProcessor(errors), context,
onWarn: messageProcessor(warns), "onError": messageProcessor(errors),
onInfo: messageProcessor(infos), "onInfo": messageProcessor(infos),
context: context "onWarn": messageProcessor(warns)
}, (err) => callback(err, { }, (err) => callback(err, {
errors: errors, errors,
warns: warns, infos,
infos: infos, messages,
messages: messages warns
})); }));
processor.process(); processor.process();

@ -1,14 +1,15 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", { "process": () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
@ -17,16 +18,14 @@ module.exports = (params, processor) => ({
} }
return processor.processTask({ return processor.processTask({
type: "parallel", "params": {
params: { "tasks": files.map((file) => ({
tasks: files.map((file) => ({ "name": file,
name: file, "params": { "filename": file },
type: "deletefromcode", "type": "deletefromcode"
params: {
filename: file
}
})) }))
} },
"type": "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}) })
}); });

@ -1,10 +1,11 @@
"use strict"; "use strict";
module.exports = (params, processor) => { module.exports = (params, processor) => {
const condition = (!params.owner || params.owner === processor.context.owner) && (!params.branch || params.branch === processor.context.branch || "refs/heads/" + params.branch === processor.context.branch); const condition = (!params.owner || params.owner === processor.context.owner)
const task = condition ? params.task : params.otherwise; && (!params.branch || params.branch === processor.context.branch || `refs/heads/${params.branch}` === processor.context.branch);
const task = condition
? params.task
: params.otherwise;
return { return { "process": () => processor.processTask(task || { "type": "noop" }, processor.done.bind(processor)) };
process: () => processor.processTask(task || {type: "noop"}, processor.done.bind(processor))
};
}; };

@ -1,20 +1,22 @@
"use strict"; "use strict";
const fse = require('fs-extra'); const path = require("path");
const fse = require("fs-extra");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const sourceFilePath = processor.context.exported + "/" + params.filename; const sourceFilePath = path.join(processor.context.exported, params.filename);
const targetFilePath = processor.context.release + "/" + params.filename; const targetFilePath = path.join(processor.context.release, params.filename);
processor.onInfo("Copying " + sourceFilePath + " to " + targetFilePath); processor.onInfo(`Copying ${sourceFilePath} to ${targetFilePath}`);
fse.copy(sourceFilePath, targetFilePath, (err) => { fse.copy(sourceFilePath, targetFilePath, (err) => {
if (err) { if (err) {
processor.onError("Unable to copy file: " + err); processor.onError(`Unable to copy file: ${err}`);
} else { } else {
processor.onInfo("Copied file"); processor.onInfo("Copied file");
} }
return processor.done(); return processor.done();
}); });
} }

@ -1,14 +1,15 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => glob(params.mask, { "process": () => glob(params.mask, {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
@ -17,16 +18,14 @@ module.exports = (params, processor) => ({
} }
return processor.processTask({ return processor.processTask({
type: "parallel", "params": {
params: { "tasks": files.map((file) => ({
tasks: files.map((file) => ({ "name": file,
name: file, "params": { "filename": file },
type: "copy", "type": "copy"
params: {
filename: file
}
})) }))
} },
"type": "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}) })
}); });

@ -1,35 +1,37 @@
"use strict"; "use strict";
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
const cssnano = require("cssnano"); const cssnano = require("cssnano");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const filePath = path.normalize(processor.context.exported + "/" + params.filename); const filePath = path.join(processor.context.exported, params.filename);
fs.readFile(filePath, (err, css) => { fs.readFile(filePath, (err, css) => {
if (err) { if (err) {
processor.onError("Unable to read stylesheet " + params.filename + ": " + err); processor.onError(`Unable to read stylesheet ${params.filename}: ${err}`);
return processor.done(); return processor.done();
} }
cssnano.process(css) return cssnano.process(css)
.catch((err) => { .catch((err) => {
processor.onError("Unable to uglify stylesheet: " + err); processor.onError(`Unable to uglify stylesheet: ${err}`);
processor.done(); processor.done();
}) })
.then((result) => { .then((result) => {
fs.writeFile(filePath, result.css, (err) => { fs.writeFile(filePath, result.css, (err) => {
if (err) { if (err) {
processor.onError("Unable to write uglified stylesheet for " + params.filename + ": " + err); processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${err}`);
} else { } else {
processor.onInfo("Saved uglified stylesheet for " + params.filename + "; uglified length: " + result.css.length); processor.onInfo(`Saved uglified stylesheet for ${params.filename}; uglified length: ${result.css.length}`);
} }
processor.done(); processor.done();
}); });
}); });
}); });
} }
}); });

@ -1,9 +1,9 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.cssnanoallDone) { if (processor.context.cssnanoallDone) {
processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json"); processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json");
} }
@ -11,25 +11,24 @@ module.exports = (params, processor) => ({
processor.context.cssnanoallDone = true; processor.context.cssnanoallDone = true;
glob("**/*.css", { glob("**/*.css", {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
type: params.preventParallelTests ? "sequential" : "parallel", "params": {
params: { "tasks": files.map((file) => ({
tasks: files.map((file) => ({ "name": file,
name: file, "params": { "filename": file },
type: "cssnano", "type": "cssnano"
params: {
filename: file
}
})) }))
} },
"type": (params.preventParallelTests && "sequential") || "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}); });
} }

@ -1,22 +1,22 @@
"use strict"; "use strict";
const fse = require('fs-extra'); const path = require("path");
const fse = require("fs-extra");
module.exports = (params, processor) => { module.exports = (params, processor) => ({
return { "process": () => {
process: () => { const sourceFilePath = path.join(processor.context.exported, params.filename);
var sourceFilePath = processor.context.exported + "/" + params.filename;
processor.onInfo("Deleting " + sourceFilePath); processor.onInfo(`Deleting ${sourceFilePath}`);
fse.remove(sourceFilePath, function(err) { fse.remove(sourceFilePath, (err) => {
if (err) { if (err) {
processor.onError("Unable to delete file: " + err); processor.onError(`Unable to delete file: ${err}`);
} else { } else {
processor.onInfo("Deleted file"); processor.onInfo("Deleted file");
} }
return processor.done();
}); return processor.done();
} });
}; }
}; });

@ -1,17 +1,17 @@
"use strict"; "use strict";
const sequential = require('./sequential'); const sequential = require("./sequential");
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ "tasks": [
{ {
type: "dotnetbuildwithoutcleanup", "name": "build",
name: "build", params,
params: params "type": "dotnetbuildwithoutcleanup"
}, },
{ {
type: "cleanupafterdotnetbuild", "name": "cleanup",
name: "cleanup" "type": "cleanupafterdotnetbuild"
} }
] ]
}, processor); }, processor);

@ -3,20 +3,20 @@
const sequential = require("./sequential"); const sequential = require("./sequential");
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ "tasks": [
{ {
type: "dotnetbuildwithoutcleanup", "name": "build",
name: "build", params,
params: params "type": "dotnetbuildwithoutcleanup"
}, },
{ {
type: "dotnetnunitall", "name": "test",
name: "test", params,
params: params "type": "dotnetnunitall"
}, },
{ {
type: "cleanupafterdotnetbuild", "name": "cleanup",
name: "cleanup" "type": "cleanupafterdotnetbuild"
} }
] ]
}, processor); }, processor);

@ -1,43 +1,52 @@
"use strict"; "use strict";
const spawn = require('child_process').spawn; const spawn = require("child_process").spawn;
const settings = require("../../settings"); const settings = require("../../settings");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
let result = ""; let result = "";
let error = ""; let error = "";
const builder = spawn(settings.builderExecutable, [params.command]); const builder = spawn(settings.builderExecutable, [params.command]);
processor.onInfo("DotNetBuilderWrapper processing (at " + (new Date().toISOString()) + "): " + JSON.stringify(params, null, 4)); processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${JSON.stringify(params, null, 4)}`);
builder.stdout.on('data', (data) => result += data); builder.stdout.on("data", (data) => {
builder.stderr.on('data', (data) => error += data); result += data;
builder.on('exit', (code) => { });
builder.stderr.on("data", (data) => {
error += data;
});
builder.on("exit", (code) => {
if (code !== 0) { if (code !== 0) {
error = "Return code is " + code + "\r\n" + error; error = `Return code is ${code}\r\n${error}`;
processor.onError(error); processor.onError(error);
return processor.done(); return processor.done();
} }
const report = JSON.parse(result); const report = JSON.parse(result);
const messages = report.Messages; const messages = report.Messages;
messages.forEach((message) => { messages.forEach((message) => {
if (!message) { if (!message) {
return processor.onError("Message is null"); return processor.onError("Message is null");
} }
switch(message.Type) { switch (message.Type) {
case "info": case "info":
return processor.onInfo(message.Body); return processor.onInfo(message.Body);
case "warn": case "warn":
return processor.onWarn(message.Body); return processor.onWarn(message.Body);
default: default:
return processor.onError(message.Body); return processor.onError(message.Body);
} }
}); });
processor.onInfo("Done DotNetBuilderWrapper processing (at " + (new Date().toISOString()) + ")"); processor.onInfo(`Done DotNetBuilderWrapper processing (at ${new Date().toISOString()})`);
return processor.done(); return processor.done();
}); });

@ -1,42 +1,40 @@
"use strict"; "use strict";
const sequential = require('./sequential'); const sequential = require("./sequential");
module.exports = (params, processor) => { module.exports = (params, processor) => {
const tasks = []; const tasks = [];
if (!params.skipMbsCheckStyle) { if (!params.skipMbsCheckStyle) {
tasks.push({ tasks.push({
type: "dotnetcheckstyle", params,
params: params "type": "dotnetcheckstyle"
}); });
} }
tasks.push({ tasks.push({
type: "dotnetrewrite", params,
params: params "type": "dotnetrewrite"
}); });
if (!params.skipNugetRestore) { if (!params.skipNugetRestore) {
tasks.push({ tasks.push({
type: "dotnetnugetrestore", params,
params: params "type": "dotnetnugetrestore"
}); });
} }
tasks.push({ tasks.push({
type: "dotnetcompile", "params": {
params: { "configuration": params.configuration,
solution: params.solution, "forceCodeAnalysis": params.forceCodeAnalysis,
skipCodeSigning: params.skipCodeSigning, "ignoreCodeAnalysis": params.ignoreCodeAnalysis,
forceCodeAnalysis: params.forceCodeAnalysis, "skipCodeSigning": params.skipCodeSigning,
ignoreCodeAnalysis: params.ignoreCodeAnalysis, "solution": params.solution,
configuration: params.configuration, "target": "Rebuild"
target: "Rebuild" },
} "type": "dotnetcompile"
}); });
return sequential({ return sequential({ tasks }, processor);
tasks: tasks
}, processor);
}; };

@ -1,61 +1,74 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const async = require('async'); const fs = require("fs");
const glob = require('glob'); const async = require("async");
const glob = require("glob");
const autoGeneratedMarker = const autoGeneratedMarker
"//------------------------------------------------------------------------------" + "\n" + = "//------------------------------------------------------------------------------\n"
"// <auto-generated>"; + "// <auto-generated>";
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.dotnetcheckerDone) { if (processor.context.dotnetcheckerDone) {
return processor.done(); return processor.done();
} }
processor.context.dotnetcheckerDone = true; processor.context.dotnetcheckerDone = true;
glob("**/*.cs", {cwd: processor.context.exported}, (err, files) => { return glob("**/*.cs", { "cwd": processor.context.exported }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
processor.onInfo("Found " + files.length + " .cs files"); processor.onInfo(`Found ${files.length} .cs files`);
if (!files || !files.length) { if (!files || !files.length) {
processor.onWarn("No .cs files found"); processor.onWarn("No .cs files found");
return processor.done(); return processor.done();
} }
return async.parallel(files.map((file) => (callback) => fs.readFile(processor.context.exported + "/" + file, { encoding: "utf8" }, (err, data) => { return async.parallel(files.map((file) => (callback) => fs.readFile(path.join(processor.context.exported, file), { "encoding": "utf8" }, (err, data) => {
if (err) { if (err) {
processor.onError("Unable to check file " + file + ": " + err); processor.onError(`Unable to check file ${file}: ${err}`);
return callback(err); return callback(err);
} }
if (data.indexOf("\r\n") >= 0) { if (data.indexOf("\r\n") >= 0) {
processor.onError("Windows-style EOL (0D0A) found in file " + file); processor.onError(`Windows-style EOL (0D0A) found in file ${file}`);
return callback(); return callback();
} }
if (params.ignoreCodeStyle) { if (params.ignoreCodeStyle) {
return callback(); return callback();
} }
if (data.substr(1, autoGeneratedMarker.length) === autoGeneratedMarker || data.substr(0, autoGeneratedMarker.length) === autoGeneratedMarker) {
processor.onInfo("Skipping auto-generated file " + file); if (
data.substr(1, autoGeneratedMarker.length) === autoGeneratedMarker
|| data.substr(0, autoGeneratedMarker.length) === autoGeneratedMarker
) {
processor.onInfo(`Skipping auto-generated file ${file}`);
return callback(); return callback();
} }
if (data.indexOf("\t") >= 0 && data.indexOf(" ") >= 0) { if (data.indexOf("\t") >= 0 && data.indexOf(" ") >= 0) {
processor.onError("Both tabs and spaces found in file " + file); processor.onError(`Both tabs and spaces found in file ${file}`);
} }
if (data.indexOf("\t") >= 0) { if (data.indexOf("\t") >= 0) {
processor.onError("Tabs found in file " + file); processor.onError(`Tabs found in file ${file}`);
} }
processor.onInfo("Checked file " + file); processor.onInfo(`Checked file ${file}`);
callback();
return callback();
})), processor.done.bind(processor)); })), processor.done.bind(processor));
}); });
} }

@ -1,33 +1,35 @@
"use strict"; "use strict";
const settings = require('../../settings'); const path = require("path");
const dotnetbuilderwrapper = require('./dotnetbuilderwrapper'); const settings = require("../../settings");
const dotnetbuilderwrapper = require("./dotnetbuilderwrapper");
module.exports = (params, processor) => { module.exports = (params, processor) => {
const compileParams = { const compileParams = {
command: "compile", "Configuration": params.configuration,
SolutionPath: processor.context.exported + "/" + params.solution, "OutputDirectory": params.overrideOutputDirectory,
Configuration: params.configuration, "SolutionPath": path.join(processor.context.exported, params.solution),
Target: params.target, "Target": params.target,
OutputDirectory: params.overrideOutputDirectory "command": "compile"
}; };
if (!settings.skipCodeSigning && !params.skipCodeSigning) { if (!settings.skipCodeSigning && !params.skipCodeSigning) {
compileParams.SigningKey = settings.codeSigningKeyFile; compileParams.SigningKey = settings.codeSigningKeyFile;
} }
if (settings.isCodeAnalysisUnsupported) {
if (params.forceCodeAnalysis) { if (settings.isCodeAnalysisUnsupported && params.forceCodeAnalysis) {
processor.onError("Code analysis is not supported"); processor.onError("Code analysis is not supported");
processor.done();
return; return processor.done();
} }
if (
settings.isCodeAnalysisUnsupported
|| params.ignoreCodeAnalysis
|| (settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis)
) {
compileParams.SkipCodeAnalysis = true; compileParams.SkipCodeAnalysis = true;
} else {
if (settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis) {
compileParams.SkipCodeAnalysis = true;
}
if (params.ignoreCodeAnalysis) {
compileParams.SkipCodeAnalysis = true;
}
} }
return dotnetbuilderwrapper(compileParams, processor); return dotnetbuilderwrapper(compileParams, processor);
}; };

@ -1,28 +1,39 @@
"use strict"; "use strict";
const sequential = require('./sequential'); const path = require("path");
const sequential = require("./sequential");
const addPostfix = (version, params, processor) => {
if (params.withoutCommitSha) {
return version;
}
return `${version}-r${processor.context.rev.substr(0, 16)}`;
};
module.exports = (params, processor) => { module.exports = (params, processor) => {
const date = new Date(); const date = new Date();
const version = (params.version || ((params.major || "0") + "." + (date.getFullYear() * 10000 + (date.getMonth() + 1) * 100 + date.getDate()) + "." + ((date.getHours() * 100 + date.getMinutes()) * 100 + date.getSeconds()))) + (params.withoutCommitSha ? "" : ("-r" + processor.context.rev.substr(0, 16))); const major = params.major || "0";
const minor = (date.getFullYear() * 10000) + ((date.getMonth() + 1) * 100) + date.getDate();
const build = (date.getHours() * 10000) + (date.getMinutes() * 100) + date.getSeconds();
const version = addPostfix(params.version || `${major}.${minor}.${build}`, params, processor);
const nupkg = `${params.name}.${version}.nupkg`;
return sequential({ return sequential({
tasks: [ "tasks": [
{ {
type: "dotnetbuilderwrapper", "params": {
params: { "BaseDirectory": processor.context.exported,
command: "nugetpack", "OutputDirectory": processor.context.exported,
BaseDirectory: processor.context.exported, "SpecPath": path.join(processor.context.exported, params.nuspec),
SpecPath: processor.context.exported + "/" + params.nuspec, "Version": version,
OutputDirectory: processor.context.exported, "command": "nugetpack"
Version: version },
} "type": "dotnetbuilderwrapper"
}, },
{ {
type: "copy", "params": { "filename": nupkg },
params: { "type": "copy"
filename: params.name + "." + version + ".nupkg"
}
} }
] ]
}, processor); }, processor);

@ -1,30 +1,30 @@
"use strict"; "use strict";
const conditional = require('./conditional'); const conditional = require("./conditional");
module.exports = (params, processor) => conditional({ module.exports = (params, processor) => conditional({
owner: params.masterRepoOwner, "branch": "master",
branch: "master", "otherwise": {
task: { "name": "nuget-pack",
name: "nuget-push", "params": {
type: "dotnetnugetpush", "major": params.major,
params: { "name": params.nuspecName,
nuspec: params.nuspecName + ".nuspec", "nuspec": `${params.nuspecName}.nuspec`,
name: params.nuspecName, "version": params.version,
withoutCommitSha: params.withoutCommitSha, "withoutCommitSha": params.withoutCommitSha
version: params.version, },
major: params.major "type": "dotnetnugetpack"
}
}, },
otherwise: { "owner": params.masterRepoOwner,
name: "nuget-pack", "task": {
type: "dotnetnugetpack", "name": "nuget-push",
params: { "params": {
nuspec: params.nuspecName + ".nuspec", "major": params.major,
name: params.nuspecName, "name": params.nuspecName,
withoutCommitSha: params.withoutCommitSha, "nuspec": `${params.nuspecName}.nuspec`,
version: params.version, "version": params.version,
major: params.major "withoutCommitSha": params.withoutCommitSha
} },
"type": "dotnetnugetpush"
} }
}, processor); }, processor);

@ -1,29 +1,39 @@
"use strict"; "use strict";
const path = require("path");
const sequential = require("./sequential"); const sequential = require("./sequential");
const addPostfix = (version, params, processor) => {
if (params.withoutCommitSha) {
return version;
}
return `${version}-r${processor.context.rev.substr(0, 16)}`;
};
module.exports = (params, processor) => { module.exports = (params, processor) => {
const date = new Date(); const date = new Date();
const version = (params.version || ((params.major || "0") + "." + (date.getFullYear() * 10000 + (date.getMonth() + 1) * 100 + date.getDate()) + "." + ((date.getHours() * 100 + date.getMinutes()) * 100 + date.getSeconds()))) + (params.withoutCommitSha ? "" : ("-r" + processor.context.rev.substr(0, 16))); const major = params.major || "0";
const nupkg = params.name + "." + version + ".nupkg"; const minor = (date.getFullYear() * 10000) + ((date.getMonth() + 1) * 100) + date.getDate();
const build = (date.getHours() * 10000) + (date.getMinutes() * 100) + date.getSeconds();
const version = addPostfix(params.version || `${major}.${minor}.${build}`, params, processor);
const nupkg = `${params.name}.${version}.nupkg`;
return sequential({ return sequential({
tasks: [ "tasks": [
{ {
type: "dotnetbuilderwrapper", "params": {
params: { "BaseDirectory": processor.context.exported,
command: "nugetpack", "OutputDirectory": processor.context.exported,
BaseDirectory: processor.context.exported, "SpecPath": path.join(processor.context.exported, params.nuspec),
SpecPath: processor.context.exported + "/" + params.nuspec, "Version": version,
OutputDirectory: processor.context.exported, "command": "nugetpack"
Version: version },
} "type": "dotnetbuilderwrapper"
}, },
{ {
type: "dotnetnugetpushonly", "params": { "Package": nupkg },
params: { "type": "dotnetnugetpushonly"
Package: nupkg
}
} }
] ]
}, processor); }, processor);

@ -1,11 +1,12 @@
"use strict"; "use strict";
const dotnetbuilderwrapper = require('./dotnetbuilderwrapper'); const path = require("path");
const dotnetbuilderwrapper = require("./dotnetbuilderwrapper");
const settings = require("../../settings"); const settings = require("../../settings");
module.exports = (params, processor) => dotnetbuilderwrapper({ module.exports = (params, processor) => dotnetbuilderwrapper({
command: "nugetpush", "ApiKey": settings.nugetApiKey,
Package: processor.context.exported + "/" + params.Package, "NugetHost": settings.nugetHost,
NugetHost: settings.nugetHost, "Package": path.join(processor.context.exported, params.Package),
ApiKey: settings.nugetApiKey "command": "nugetpush"
}, processor); }, processor);

@ -1,16 +1,17 @@
"use strict"; "use strict";
const sequential = require('./sequential'); const path = require("path");
const sequential = require("./sequential");
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ "tasks": [
{ {
type: "dotnetbuilderwrapper", "params": {
params: { "BaseDirectory": processor.context.exported,
command: "nugetrestore", "SolutionPath": path.join(processor.context.exported, params.solution),
BaseDirectory: processor.context.exported, "command": "nugetrestore"
SolutionPath: processor.context.exported + "/" + params.solution },
} "type": "dotnetbuilderwrapper"
} }
] ]
}, processor); }, processor);

@ -1,9 +1,9 @@
"use strict"; "use strict";
const dotNetBuilderWrapper = require('./dotnetbuilderwrapper'); const path = require("path");
const dotNetBuilderWrapper = require("./dotnetbuilderwrapper");
module.exports = (params, processor) => dotNetBuilderWrapper({ module.exports = (params, processor) => dotNetBuilderWrapper({
command: "nunit", "TestLibraryPath": path.join(processor.context.exported, params.assembly),
TestLibraryPath: processor.context.exported + "/" + params.assembly//, "command": "nunit"
// OutputPath: processor.context.release + "/" + params.solution + "/"
}, processor); }, processor);

@ -1,9 +1,9 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.dotnetnunitallDone) { if (processor.context.dotnetnunitallDone) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json"); processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
} }
@ -11,30 +11,30 @@ module.exports = (params, processor) => ({
processor.context.dotnetnunitallDone = true; processor.context.dotnetnunitallDone = true;
glob("**/{bin,build}/**/*.{Tests,Test,UnitTests}.dll", { glob("**/{bin,build}/**/*.{Tests,Test,UnitTests}.dll", {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
if (!files || !files.length) { if (!files || !files.length) {
processor.onError("No test assemblies found in " + processor.context.exported); processor.onError(`No test assemblies found in ${processor.context.exported}`);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
type: params.preventParallelTests ? "sequential" : "parallel", "params": {
params: { "tasks": files.map((file) => ({
tasks: files.map((file) => ({ "name": file,
name: file, "params": { "assembly": file },
type: "dotnetnunit", "type": "dotnetnunit"
params: {
assembly: file
}
})) }))
} },
"type": (params.preventParallelTests && "sequential") || "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}); });
} }

@ -1,47 +1,48 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const Mustache = require('mustache'); const fs = require("fs");
const Mustache = require("mustache");
const sequential = require('./sequential'); const sequential = require("./sequential");
const msbuildTemplate = fs.readFileSync(__dirname + "/dotnetpackwebapp.template.msbuild", {encoding: "utf8"}); const msbuildTemplate = fs.readFileSync(path.join(__dirname, "/dotnetpackwebapp.template.msbuild"), { "encoding": "utf8" });
const deployTemplate = fs.readFileSync(__dirname + "/dotnetpackwebapp.template.bat", {encoding: "utf8"}); const deployTemplate = fs.readFileSync(path.join(__dirname, "/dotnetpackwebapp.template.bat"), { "encoding": "utf8" });
const versionTemplate = fs.readFileSync(__dirname + "/dotnetpackwebapp.template.version.aspx", {encoding: "utf8"}); const versionTemplate = fs.readFileSync(path.join(__dirname, "/dotnetpackwebapp.template.version.aspx"), { "encoding": "utf8" });
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ "tasks": [
{ {
type: "writefile", "params": {
params: { "data": Mustache.render(msbuildTemplate, params),
filename: "MakePackage.msbuild", "filename": "MakePackage.msbuild"
data: Mustache.render(msbuildTemplate, params) },
} "type": "writefile"
}, },
{ {
type: "writefile", "params": {
params: { "data": Mustache.render(deployTemplate, params),
filename: "Deploy.bat", "filename": "Deploy.bat"
data: Mustache.render(deployTemplate, params) },
} "type": "writefile"
}, },
{ {
type: "writefile", "params": {
params: { "data": Mustache.render(versionTemplate, params),
filename: "version.aspx", "filename": "version.aspx"
data: Mustache.render(versionTemplate, params) },
} "type": "writefile"
}, },
{ {
type: "dotnetcompile", "params": {
params: { "configuration": params.configuration,
solution: "MakePackage.msbuild", "isCodeAnalysisUnsupported": params.isCodeAnalysisUnsupported,
skipCodeSigning: params.skipCodeSigning, "overrideOutputDirectory": processor.context.release,
isCodeAnalysisUnsupported: params.isCodeAnalysisUnsupported, "skipCodeSigning": params.skipCodeSigning,
configuration: params.configuration, "solution": "MakePackage.msbuild",
target: "Package", "target": "Package"
overrideOutputDirectory: processor.context.release },
} "type": "dotnetcompile"
} }
] ]
}, processor); }, processor);

@ -1,57 +1,60 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const async = require('async'); const fs = require("fs");
const glob = require('glob'); const async = require("async");
const settings = require('../../settings'); const glob = require("glob");
const settings = require("../../settings");
const addAssemblyAttribute = (content, attribute) => content + "\n" + attribute + "\n";
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.dotnetrewriterDone) { if (processor.context.dotnetrewriterDone) {
return processor.done(); return processor.done();
} }
processor.context.dotnetrewriterDone = true; processor.context.dotnetrewriterDone = true;
const processAssemblyInfo = (appendInformationalVersion) => (content, cb) => { const processAssemblyInfo = (appendInformationalVersion) => (originalContent, cb) => {
let content = originalContent;
if (!params.skipCodeSigning && !settings.skipCodeSigning) { if (!params.skipCodeSigning && !settings.skipCodeSigning) {
content = content.replace( content = content.replace(
/InternalsVisibleTo\s*\(\s*"([\w.]+)"\s*\)/g, /InternalsVisibleTo\s*\(\s*"([\w.]+)"\s*\)/g,
(match, p1) => "InternalsVisibleTo(\"" + p1 + ",PublicKey=" + settings.codeSigningPublicKey + "\")" (match, p1) => `InternalsVisibleTo("${p1},PublicKey=${settings.codeSigningPublicKey}")`
); );
} }
if (appendInformationalVersion) { if (appendInformationalVersion) {
content = addAssemblyAttribute(content, "[assembly: System.Reflection.AssemblyInformationalVersion(\"" + processor.context.versionInfo + "\")]"); content = `${content}\n[assembly: System.Reflection.AssemblyInformationalVersion("${processor.context.versionInfo}")]`;
} }
return cb(null, content); return cb(null, content);
}; };
glob("**/{InternalsVisible,AssemblyInfo}*.cs", {cwd: processor.context.exported}, (err, files) => { return glob("**/{InternalsVisible,AssemblyInfo}*.cs", { "cwd": processor.context.exported }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
processor.onInfo("Found " + files.length + " AssemblyInfo.cs files"); processor.onInfo(`Found ${files.length} AssemblyInfo.cs files`);
if (!files || !files.length) { if (!files || !files.length) {
processor.onWarn("No AssemblyInfo.cs found"); processor.onWarn("No AssemblyInfo.cs found");
return processor.done(); return processor.done();
} }
return async.parallel(files.map((file) => (callback) => async.waterfall([ return async.parallel(files.map((file) => (callback) => async.waterfall([
fs.readFile.bind(null, processor.context.exported + "/" + file, { encoding: "utf8" }), fs.readFile.bind(null, path.join(processor.context.exported, file), { "encoding": "utf8" }),
processAssemblyInfo(file.toLowerCase().indexOf("assemblyinfo.cs") >= 0), processAssemblyInfo(file.toLowerCase().indexOf("assemblyinfo.cs") >= 0),
fs.writeFile.bind(null, processor.context.exported + "/" + file) fs.writeFile.bind(null, path.join(processor.context.exported, file))
], (err) => { ], (err) => {
if (err) { if (err) {
processor.onError("Unable to rewrite file " + file + ": " + err); processor.onError(`Unable to rewrite file ${file}: ${err}`);
} else { } else {
processor.onInfo("Rewritten file " + file); processor.onInfo(`Rewritten file ${file}`);
} }
callback(err); callback(err);
})), processor.done.bind(processor)); })), processor.done.bind(processor));

@ -1,7 +1,7 @@
"use strict"; "use strict";
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (params.error) { if (params.error) {
processor.onError(params.error); processor.onError(params.error);
} }

@ -1,22 +1,21 @@
"use strict"; "use strict";
const fs = require('fs'); const path = require("path");
const path = require('path');
const CLIEngine = require("eslint").CLIEngine; const CLIEngine = require("eslint").CLIEngine;
const settings = require("../../settings"); const settings = require("../../settings");
const cli = new CLIEngine({ const cli = new CLIEngine({ "configFile": settings.eslintBrowserConfig });
configFile: settings.eslintBrowserConfig
});
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const filePath = path.normalize(processor.context.exported + "/" + params.filename); const filePath = path.join(processor.context.exported, params.filename);
const result = cli.executeOnFiles([filePath]); const result = cli.executeOnFiles([filePath]);
processor.onInfo("ESLinted " + params.filename);
processor.onInfo(`ESLinted ${params.filename}`);
result.results.forEach((subresult) => { result.results.forEach((subresult) => {
subresult.messages.forEach((message) => { subresult.messages.forEach((message) => {
const messageText = params.filename + ":" + message.line + "," + message.column + " (" + message.ruleId + ") " + message.message; const messageText = `${params.filename}:${message.line},${message.column} (${message.ruleId}) ${message.message}`;
if (message.fatal || message.severity === 2) { if (message.fatal || message.severity === 2) {
processor.onError(messageText); processor.onError(messageText);
} else { } else {

@ -1,9 +1,9 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.eslintbrowserallDone) { if (processor.context.eslintbrowserallDone) {
processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json"); processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json");
} }
@ -13,25 +13,24 @@ module.exports = (params, processor) => ({
const excludeFiles = params.excludeFiles || []; const excludeFiles = params.excludeFiles || [];
glob("**/*.js", { glob("**/*.js", {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
type: params.preventParallelTests ? "sequential" : "parallel", "params": {
params: { "tasks": files.filter((file) => !excludeFiles.includes(file)).map((file) => ({
tasks: files.filter(file => !excludeFiles.includes(file)).map((file) => ({ "name": file,
name: file, "params": { "filename": file },
type: "eslintbrowser", "type": "eslintbrowser"
params: {
filename: file
}
})) }))
} },
"type": (params.preventParallelTests && "sequential") || "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}); });
} }

@ -1,5 +1,3 @@
"use strict"; "use strict";
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({ "process": () => processor.done() });
process: () => processor.done()
});

@ -1,34 +1,28 @@
"use strict"; "use strict";
const sequential = require('./sequential'); const sequential = require("./sequential");
module.exports = (params, processor) => sequential({ module.exports = (params, processor) => sequential({
tasks: [ "tasks": [
{ {
type: "eslintbrowserall", "params": { "excludeFiles": params.eslintExcludeFiles },
params: { "type": "eslintbrowserall"
excludeFiles: params.eslintExcludeFiles
}
}, },
{ "type": "uglifyjsall" },
{ "type": "cssnanoall" },
{ {
type: "uglifyjsall" "params": {
"data": processor.context.versionInfo,
"filename": "version.txt"
},
"type": "writefile"
}, },
{ {
type: "cssnanoall" "params": {
}, "archive": `${processor.context.reponame}.zip`,
{ "directory": ""
type: "writefile", },
params: { "type": "zip"
filename: "version.txt",
data: processor.context.versionInfo
}
},
{
type: "zip",
params: {
directory: "",
archive: processor.context.reponame + ".zip"
}
} }
] ]
}, processor); }, processor);

@ -2,6 +2,6 @@
const async = require("async"); const async = require("async");
module.exports = (params, processor) => ({ const mapper = (processor) => (task) => (callback) => processor.processTask(task, callback);
process: () => async.parallel(params.tasks.map((task) => (callback) => processor.processTask(task, (err) => callback())), processor.done.bind(processor))
}); module.exports = (params, processor) => ({ "process": () => async.parallel(params.tasks.map(mapper(processor)), () => processor.done()) });

@ -2,9 +2,6 @@
const async = require("async"); const async = require("async");
module.exports = (params, processor) => { const mapper = (processor) => (task) => (callback) => processor.processTask(task, callback);
const mapper = Function.bind.bind(processor.processTask, processor);
return { module.exports = (params, processor) => ({ "process": () => async.series(params.tasks.map(mapper(processor)), () => processor.done()) });
process: () => async.series(params.tasks.map(mapper), processor.done.bind(processor))
};
};

@ -1,18 +1,19 @@
"use strict"; "use strict";
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
const UglifyJS = require("uglify-js"); const UglifyJS = require("uglify-js");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const filePath = path.normalize(processor.context.exported + "/" + params.filename); const filePath = path.normalize(path.join(processor.context.exported, params.filename));
const result = UglifyJS.minify(filePath); const result = UglifyJS.minify(filePath);
fs.writeFile(filePath, result.code, (err) => { fs.writeFile(filePath, result.code, (err) => {
if (err) { if (err) {
processor.onError("Unable to write uglified script for " + params.filename + ": " + err); processor.onError(`Unable to write uglified script for ${params.filename}: ${err}`);
} else { } else {
processor.onInfo("Saved uglified script for " + params.filename + "; uglified length: " + result.code.length); processor.onInfo(`Saved uglified script for ${params.filename}; uglified length: ${result.code.length}`);
} }
processor.done(); processor.done();

@ -1,9 +1,9 @@
"use strict"; "use strict";
const glob = require('glob'); const glob = require("glob");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
if (processor.context.uglifyjsallDone) { if (processor.context.uglifyjsallDone) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json"); processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
} }
@ -11,25 +11,24 @@ module.exports = (params, processor) => ({
processor.context.uglifyjsallDone = true; processor.context.uglifyjsallDone = true;
glob("**/*.js", { glob("**/*.js", {
dot: true, "cwd": processor.context.exported,
cwd: processor.context.exported "dot": true
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
type: params.preventParallelTests ? "sequential" : "parallel", "params": {
params: { "tasks": files.map((file) => ({
tasks: files.map((file) => ({ "name": file,
name: file, "params": { "filename": file },
type: "uglifyjs", "type": "uglifyjs"
params: {
filename: file
}
})) }))
} },
"type": (params.preventParallelTests && "sequential") || "parallel"
}, processor.done.bind(processor)); }, processor.done.bind(processor));
}); });
} }

@ -1,18 +1,21 @@
"use strict"; "use strict";
const fs = require('fs'); const fs = require("fs");
const path = require("path");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const filePath = processor.context.exported + "/" + params.filename; const filePath = path.join(processor.context.exported, params.filename);
processor.onInfo("Writing to " + filePath);
processor.onInfo(`Writing to ${filePath}`);
fs.writeFile(filePath, params.data, (err) => { fs.writeFile(filePath, params.data, (err) => {
if (err) { if (err) {
processor.onError("Unable to write file: " + err); processor.onError(`Unable to write file: ${err}`);
} else { } else {
processor.onInfo("Written file"); processor.onInfo("Written file");
} }
return processor.done(); return processor.done();
}); });
} }

@ -1,22 +1,22 @@
"use strict"; "use strict";
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
const Archiver = require('archiver'); const Archiver = require("archiver");
module.exports = (params, processor) => ({ module.exports = (params, processor) => ({
process: () => { "process": () => {
const sourceDirectoryPath = path.normalize(processor.context.exported + "/" + (params.directory || "")); const sourceDirectoryPath = path.normalize(path.join(processor.context.exported, params.directory || ""));
const targetArchivePath = path.normalize(processor.context.release + "/" + params.archive); const targetArchivePath = path.normalize(path.join(processor.context.release, params.archive));
processor.onInfo("Compressing '" + params.directory + "' to " + params.archive); processor.onInfo(`Compressing "${params.directory}" to "${params.archive}"`);
const output = fs.createWriteStream(targetArchivePath); const output = fs.createWriteStream(targetArchivePath);
const archive = new Archiver("zip"); const archive = new Archiver("zip");
output.on("close", () => processor.done()); output.on("close", () => processor.done());
archive.on("error", (err) => processor.onError("Error while compressing: " + err)); archive.on("error", (err) => processor.onError(`Error while compressing: ${err}`));
archive.pipe(output); archive.pipe(output);
archive.directory(sourceDirectoryPath, false); archive.directory(sourceDirectoryPath, false);
archive.finalize(); archive.finalize();

@ -2,13 +2,15 @@
module.exports = (req, res) => { module.exports = (req, res) => {
const options = { const options = {
owner: req.params.owner, "branch": `/refs/heads/${req.params.branch}`,
reponame: req.params.reponame, "branchName": req.params.branch,
branchName: req.params.branch, "file": req.params[0],
branch: "/refs/heads/" + req.params.branch, "owner": req.params.owner,
rev: req.params.rev, "reponame": req.params.reponame,
file: req.params[0] "rev": req.params.rev
}; };
res.sendfile(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/" + options.file); const pathParts = [req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev, options.file];
res.sendfile(pathParts.join("/"));
}; };

@ -1,9 +1,9 @@
"use strict"; "use strict";
exports.index = (req, res) => res.render('index', { title: 'Express' + req + "qq" }); exports.index = (req, res) => res.render("index", { "title": `Express<br/>\r\n${req}` });
exports.postreceive = require('./postreceive'); exports.postreceive = require("./postreceive");
exports.manual = require('./manual'); exports.manual = require("./manual");
exports.status = require('./status'); exports.status = require("./status");
exports.artifact = require('./artifact'); exports.artifact = require("./artifact");
exports.release = require('./release'); exports.release = require("./release");

@ -1,20 +1,21 @@
"use strict"; "use strict";
const builder = require('../lib/builder'); const builder = require("../lib/builder");
exports.get = (req, res) => res.render('manual'); exports.get = (req, res) => res.render("manual");
exports.post = (req, res) => { exports.post = (req, res) => {
const options = req.body; const options = req.body;
options.url = "https://pos-github.payonline.ru/" + options.owner + "/" + options.reponame;
options.url = `https://pos-github.payonline.ru/${options.owner}/${options.reponame}`;
options.app = req.app; options.app = req.app;
builder.build(options, (err, result) => { builder.build(options, (err, result) => {
console.log("Done processing manual request"); console.log("Done processing manual request");
console.log("Error: " + err); console.log(`Error: ${err}`);
//console.log("Result:"); res.render("manual-done", {
//console.log(result); err,
res.render('manual-done', {err: err, result: result}); result
//res.render("manual-done", { err: err, result: result }); });
}); });
}; };

@ -1,27 +1,27 @@
"use strict"; "use strict";
const builder = require('../lib/builder'); const builder = require("../lib/builder");
const commenter = require('../lib/commenter'); const commenter = require("../lib/commenter");
const getBranchDescription = (options) => `${options.owner}/${options.reponame}:${options.branchname || options.branch}`;
const processPush = (req, res, payload) => { const processPush = (req, res, payload) => {
const repository = payload.repository; const repository = payload.repository;
const options = { const options = {
app: req.app, "app": req.app,
url: repository.url, "branch": payload.ref,
owner: repository.owner.name, "owner": repository.owner.name,
reponame: repository.name, "reponame": repository.name,
rev: payload.after, "rev": payload.after,
branch: payload.ref "url": repository.url
}; };
console.log("Got push event for " + options.owner + "/" + options.reponame + ":" + options.branch); console.log(`Got push event for ${getBranchDescription(options)}`);
builder.build(options, (err, result) => { builder.build(options, (err, result) => {
console.log("Done processing request from GitHub"); console.log("Done processing request from GitHub");
console.log("Error: " + err); console.log(`Error: ${err}`);
//console.log("Result:"); res.send(`Done processing request from GitHub\r\nError: ${err}\r\nResult: ${result}`);
//console.log(result);
res.send("Done processing request from GitHub\r\n" + "Error: " + err + "\r\n" + "Result: " + result);
}); });
}; };
@ -32,45 +32,45 @@ const processPullRequest = (req, res, payload) => {
const head = pullRequest.head; const head = pullRequest.head;
const headRepo = head.repo; const headRepo = head.repo;
const headRepoOptions = { const headRepoOptions = {
url: headRepo.url, "branch": `refs/heads/${head.ref}`,
owner: headRepo.owner.name || headRepo.owner.login, "branchname": head.ref,
reponame: headRepo.name, "owner": headRepo.owner.name || headRepo.owner.login,
rev: head.sha, "reponame": headRepo.name,
branchname: head.ref, "rev": head.sha,
branch: "refs/heads/" + head.ref "url": headRepo.url
}; };
const base = pullRequest.base; const base = pullRequest.base;
const baseRepo = base.repo; const baseRepo = base.repo;
const baseRepoOptions = { const baseRepoOptions = {
owner: baseRepo.owner.name || baseRepo.owner.login, "branchname": base.ref,
reponame: baseRepo.name, "owner": baseRepo.owner.name || baseRepo.owner.login,
branchname: base.ref "reponame": baseRepo.name
}; };
const options = { const options = {
app: req.app, action,
action: action, "app": req.app,
number: number, baseRepoOptions,
headRepoOptions: headRepoOptions, headRepoOptions,
baseRepoOptions: baseRepoOptions number
}; };
const masterOptions = { const masterOptions = {
app: req.app, action,
action: action, "app": req.app,
number: number, baseRepoOptions,
headRepoOptions: baseRepoOptions, "headRepoOptions": baseRepoOptions,
baseRepoOptions: baseRepoOptions number
}; };
console.log("Got pull request " + action + " event, from " + headRepoOptions.owner + "/" + headRepoOptions.reponame + ":" + headRepoOptions.branchname + " (" + headRepoOptions.rev + ") to " + baseRepoOptions.owner + "/" + baseRepoOptions.reponame + ":" + baseRepoOptions.branchname); console.log(`Got pull request ${action} event, `
+ `from ${getBranchDescription(headRepoOptions)} (${headRepoOptions.rev}) to ${getBranchDescription(baseRepoOptions)}`);
if (action !== "opened" && action !== "reopened" && action !== "synchronize" && action !== "closed") { if (action !== "opened" && action !== "reopened" && action !== "synchronize" && action !== "closed") {
//console.log("Got '" + action + "' event:");
//console.log(req.body);
return res.send("Only opened/reopened/synchronize/closed actions are supported"); return res.send("Only opened/reopened/synchronize/closed actions are supported");
} }
if (action === "closed" && !pullRequest.merged) { if (action === "closed" && !pullRequest.merged) {
console.log("Pull request closed without merging"); console.log("Pull request closed without merging");
return res.send("Pull request closed without merging"); return res.send("Pull request closed without merging");
} }
@ -78,11 +78,11 @@ const processPullRequest = (req, res, payload) => {
return res.send(""); return res.send("");
} }
commenter.commentOnPullRequest( return commenter.commentOnPullRequest(
action === "closed" ? masterOptions : options, (action === "closed" && masterOptions) || options,
(err, data) => { (err, data) => {
if (err) { if (err) {
console.log("Unable to post comment: " + err); console.log(`Unable to post comment: ${err}`);
} }
res.send(err || data); res.send(err || data);
@ -96,7 +96,7 @@ module.exports = (req, res) => {
} }
const eventType = req.header("x-github-event"); const eventType = req.header("x-github-event");
const payload = req.body.payload ? JSON.parse(req.body.payload || "{}") : req.body; const payload = (req.body.payload && JSON.parse(req.body.payload)) || req.body;
if (eventType === "push") { if (eventType === "push") {
return processPush(req, res, payload); return processPush(req, res, payload);
@ -106,7 +106,7 @@ module.exports = (req, res) => {
return processPullRequest(req, res, payload); return processPullRequest(req, res, payload);
} }
console.log("Got '" + eventType + "' event:"); console.log(`Got "${eventType}" event:`);
//console.log(req.body);
return res.send("Only push/pull_request events are supported"); return res.send("Only push/pull_request events are supported");
}; };

@ -1,26 +1,30 @@
"use strict"; "use strict";
const path = require('path'); const path = require("path");
const fs = require('fs'); const fs = require("fs");
const Archiver = require('archiver'); const Archiver = require("archiver");
const getReport = (releasePath, callback) => { const getReport = (releasePath, callback) => {
const reportFile = releasePath + "report.json"; const reportFile = `${releasePath}report.json`;
fs.exists(reportFile, (exists) => { fs.exists(reportFile, (exists) => {
if (!exists) { if (!exists) {
return callback("ReportFileNotFound: " + reportFile); return callback(`ReportFileNotFound: ${reportFile}`);
} }
return fs.readFile(reportFile, (err, dataBuffer) => { return fs.readFile(reportFile, (err, dataBuffer) => {
if (err) { if (err) {
return callback(err, reportFile); return callback(err, reportFile);
} }
const data = dataBuffer.toString(); const data = dataBuffer.toString();
if (!data) { if (!data) {
return callback("ReportFileNotFound", reportFile); return callback("ReportFileNotFound", reportFile);
} }
const report = JSON.parse(data); const report = JSON.parse(data);
return callback(null, report); return callback(null, report);
}); });
}); });
@ -34,24 +38,28 @@ const getDatePart = (report) => {
const date = new Date(report.date); const date = new Date(report.date);
const paddingLeft = (str, paddingValue) => String(paddingValue + str).slice(-paddingValue.length); const paddingLeft = (str, paddingValue) => String(paddingValue + str).slice(-paddingValue.length);
return date.getFullYear() + "." + const year = date.getFullYear();
paddingLeft(date.getMonth() + 1, "00") + "." + const month = paddingLeft(date.getMonth() + 1, "00");
paddingLeft(date.getDate(), "00") + "." + const day = paddingLeft(date.getDate(), "00");
paddingLeft(date.getHours(), "00") + "." + const hours = paddingLeft(date.getHours(), "00");
paddingLeft(date.getMinutes(), "00") + "." + const minutes = paddingLeft(date.getMinutes(), "00");
paddingLeft(date.getSeconds(), "00"); const seconds = paddingLeft(date.getSeconds(), "00");
return `${year}.${month}.${day}.${hours}.${minutes}.${seconds}`;
}; };
module.exports = (req, res, next) => { module.exports = (req, res, next) => {
const options = { const options = {
owner: req.params.owner, "branch": `/refs/heads/${req.params.branch}`,
reponame: req.params.reponame, "branchName": req.params.branch,
branchName: req.params.branch, "owner": req.params.owner,
branch: "/refs/heads/" + req.params.branch, "reponame": req.params.reponame,
rev: req.params.rev "rev": req.params.rev
}; };
const releasePath = path.normalize(req.app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/"); const releasePathParts = [req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev, ""];
const releasePath = path.normalize(releasePathParts.join("/"));
getReport(releasePath, (err, report) => { getReport(releasePath, (err, report) => {
if (err) { if (err) {
@ -59,10 +67,12 @@ module.exports = (req, res, next) => {
} }
const archive = new Archiver("zip"); const archive = new Archiver("zip");
archive.on("error", next); archive.on("error", next);
res.attachment(options.reponame + '.' + getDatePart(report) + '.' + options.rev + '.zip', '.'); res.attachment(`${options.reponame}.${getDatePart(report)}.${options.rev}.zip`, ".");
archive.pipe(res); archive.pipe(res);
archive.directory(releasePath, false); archive.directory(releasePath, false);
archive.finalize();
return archive.finalize();
}); });
}; };

@ -1,31 +1,31 @@
"use strict"; "use strict";
const url = require('url'); const url = require("url");
const statusProcessor = require('../lib/status-processor'); const statusProcessor = require("../lib/status-processor");
const parseOptionsFromReferer = (path, callback) => { const parseOptionsFromReferer = (path, callback) => {
const pathParts = path.split("/").filter((value) => value); const pathParts = path.split("/").filter((value) => value);
const result = {}; const result = {};
const [, secondPart, thirdPart] = pathParts;
if (pathParts.length < 2) { if (!secondPart) {
return callback("BadRequest", result); return callback("BadRequest", result);
} }
if (pathParts[2] === "tree") { if (thirdPart === "tree") {
pathParts.splice(2, 1); [result.owner, result.reponame, , result.branchName, result.rev] = pathParts;
} else {
[result.owner, result.reponame, result.branchName, result.rev] = pathParts;
} }
result.owner = pathParts[0];
result.reponame = pathParts[1];
result.branchName = pathParts[2];
result.rev = pathParts[3];
return callback(null, result); return callback(null, result);
}; };
const createShowReport = (res) => (err, options) => { const createShowReport = (res) => (err, inputOptions) => {
options = options || {}; const options = inputOptions || {};
options.err = err; options.err = err;
res.render('status', options); res.render("status", options);
}; };
exports.image = (req, res) => { exports.image = (req, res) => {
@ -40,17 +40,19 @@ exports.image = (req, res) => {
} else if (options.report.err) { } else if (options.report.err) {
options.status = "Error"; options.status = "Error";
options.message = options.report.err; options.message = options.report.err;
} else if ((options.report.result.warns.$allMessages || []).length > 0) { } else if ((options.report.result.warns.$allMessages || []).length) {
const [firstWarn] = options.report.result.warns.$allMessages;
options.status = "Warning"; options.status = "Warning";
options.message = options.report.result.warns.$allMessages[0].message; options.message = firstWarn.message;
} else { } else {
options.status = "OK"; options.status = "OK";
if ((options.report.result.infos.$allMessages || []).length > 0) { if ((options.report.result.infos.$allMessages || []).length) {
options.message = options.report.result.infos.$allMessages[options.report.result.infos.$allMessages.length-1].message; options.message = options.report.result.infos.$allMessages[options.report.result.infos.$allMessages.length - 1].message;
} }
} }
res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader("Content-Type", "image/svg+xml");
res.render('status-image', options); res.render("status-image", options);
}; };
parseOptionsFromReferer(url.parse(req.headers.referer || "").pathname || "", (err, options) => { parseOptionsFromReferer(url.parse(req.headers.referer || "").pathname || "", (err, options) => {
@ -58,17 +60,17 @@ exports.image = (req, res) => {
return handle(err, options); return handle(err, options);
} }
statusProcessor.getReport(req.app, options, (err, options) => handle(err, options)); return statusProcessor.getReport(req.app, options, handle);
}); });
}; };
exports.page = (req, res) => { exports.page = (req, res) => {
const options = { const options = {
owner: req.params.owner, "branch": `/refs/heads/${req.params.branch}`,
reponame: req.params.reponame, "branchName": req.params.branch,
branchName: req.params.branch, "owner": req.params.owner,
branch: "/refs/heads/" + req.params.branch, "reponame": req.params.reponame,
rev: req.params.rev "rev": req.params.rev
}; };
statusProcessor.getReport(req.app, options, createShowReport(res)); statusProcessor.getReport(req.app, options, createShowReport(res));

Loading…
Cancel
Save