Major improvements

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent d2460adf36
commit e00d359249
  1. 2
      BuildServer/app.js
  2. 25
      BuildServer/lib/builder.js
  3. 105
      BuildServer/routes/status.js
  4. 15
      BuildServer/views/status-image.jade

@ -40,7 +40,7 @@ app.get('/', routes.index);
app.post('/github/postreceive', routes.postreceive); app.post('/github/postreceive', routes.postreceive);
app.get('/manual', routes.manual.get); app.get('/manual', routes.manual.get);
app.post('/manual', routes.manual.post); app.post('/manual', routes.manual.post);
app.get('/status', routes.status.image); app.get('/status/:owner/:reponame/:branch/:rev', routes.status.image);
app.get('/status.svg', routes.status.image); app.get('/status.svg', routes.status.image);
http.createServer(app).listen(app.get('port'), function(){ http.createServer(app).listen(app.get('port'), function(){

@ -18,6 +18,19 @@ var build = function (options, callback) {
fse.mkdirsSync(release); fse.mkdirsSync(release);
fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/" + branch + "/latest.id", rev);
fse.mkdirsSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs");
fs.writeFileSync(options.app.get('releasepath') + "/" + owner + "/" + reponame + "/$revs/" + rev + ".branch", branch);
var done = function (err, result) {
fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) {
if (writeErr) {
return callback(writeErr);
}
return callback(err, result);
});
};
gitLoader({ gitLoader({
remote: url + ".git", remote: url + ".git",
local: local, local: local,
@ -31,11 +44,11 @@ var build = function (options, callback) {
console.log("Done loading from git"); console.log("Done loading from git");
fs.exists(exported + "/mbs.json", function (exists) { fs.exists(exported + "/mbs.json", function (exists) {
if (!exists) { if (!exists) {
return callback(null, "MBSNotFound"); return done(null, "MBSNotFound");
} }
fs.readFile(exported + "/mbs.json", function (err, data) { fs.readFile(exported + "/mbs.json", function (err, data) {
if (err) { if (err) {
return callback(err, "MBSUnableToRead"); return done(err, "MBSUnableToRead");
} }
var task; var task;
@ -43,17 +56,15 @@ var build = function (options, callback) {
task = JSON.parse(data); task = JSON.parse(data);
} catch(err) { } catch(err) {
console.log("Malformed data: " + data); console.log("Malformed data: " + data);
return callback(err, "MBSMalformed"); return done(err, "MBSMalformed");
} }
processor.processTask(task, function (err, result) { processor.processTask(task, function (err, result) {
if (err) { if (err) {
return callback(err, result); return done(err, result);
} }
fs.writeFile(release + "/report.json", JSON.stringify(result), function (err) { return done(err, result);
return callback(err, result);
});
}); });
}); });
}); });

@ -1,5 +1,104 @@
exports.image = function(req, res){ "use strict";
console.log(req.headers);
var fs = require('fs'),
url = require('url');
var parseOptionsFromReferer = function (req, callback) {
var pathParts = (url.parse(req.headers.referer || "").pathname || "").split("/");
var result = {};
if (pathParts.length < 3) {
return callback("BadRequest", result);
}
result.owner = pathParts[1];
result.reponame = pathParts[2];
if (pathParts[3] && /^[\da-f]{40}$/i.test(pathParts[4])) {
result.rev = pathParts[4];
var branchFile = req.app.get('releasepath') + "/" + result.owner + "/" + result.reponame + "/$revs/" + result.rev + ".branch";
fs.exists(branchFile, function (exists) {
if (!exists) {
return callback("BranchFileNotFound", result);
}
fs.readFile(branchFile, function (err, data) {
if (err) {
return callback(err, result);
}
result.branch = data.toString();
result.branchName = result.branch.split("/").pop();
return callback(null, result);
});
});
} else {
result.branchName = pathParts[4] || "master";
result.branch = "refs/heads/" + result.branchName;
// console.log(result);
var revFile = req.app.get('releasepath') + "/" + result.owner + "/" + result.reponame + "/" + result.branch + "/latest.id";
fs.exists(revFile, function (exists) {
if (!exists) {
return callback("RevFileNotFound", result);
}
fs.readFile(revFile, function (err, data) {
if (err) {
return callback(err, result);
}
result.rev = data.toString();
return callback(null, result);
});
});
}
};
var loadReport = function (app, options, callback) {
var reportFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/report.json";
fs.exists(reportFile, function (exists) {
if (!exists) {
return callback("ReportFileNotFound", options);
}
fs.readFile(reportFile, function (err, data) {
if (err) {
return callback(err, options);
}
options.report = JSON.parse(data);
return callback(null, options);
});
});
};
exports.image = function(req, res) {
// console.log(req.headers);
var handle = function (err, options) {
if (err === "ReportFileNotFound") {
options.status = "Building";
} else if (err) {
options.status = "StatusError";
options.message = err;
} else if (options.report.result === "MBSNotFound") {
options.status = "MBSNotUsed";
} else if (options.report.err) {
options.status = "Error";
options.message = options.report.err;
} else if ((options.report.result.warns.$allMessages || []).length > 0) {
options.status = "Warning";
options.message = options.report.result.warns.$allMessages[0];
} else {
options.status = "OK";
}
console.log(options);
res.setHeader('Content-Type', 'image/svg+xml'); res.setHeader('Content-Type', 'image/svg+xml');
res.render('status-image', { title: 'Express' + req + "qq", status: "Error" }); res.render('status-image', options);
};
parseOptionsFromReferer(req, function (err, options) {
if (err) {
return handle(err, options);
}
loadReport(req.app, options, function (err, options) {
handle(err, options);
});
});
};
exports.page = function(req, res) {
}; };

@ -1,8 +1,13 @@
doctype xml doctype xml
-var fills = {Error: "red", Warn: "yellow", OK: "green" } -var fills = {Warn: "yellow", OK: "green" }
-var colors = {Error: "white", Warn: "black", OK: "black" } -var colors = {Warn: "black", OK: "black" }
-var fill = fills[status] || "red"
-var color = colors[status] || "white"
svg(xmlns="http://www.w3.org/2000/svg", version="1.1", width="800px", height="100px") svg(xmlns="http://www.w3.org/2000/svg", xmlns:xlink="http://www.w3.org/1999/xlink", version="1.1", width="800px", height=(message?"100px":"80px"))
rect(width="100%", height="100%", fill=fills[status]) a(xlink:href="/status/" + [owner, reponame, branchName, rev].join("/"))
text(x=20, y=50, font-size=36, font-weight="bold", fill=colors[status]) Build status: #{status} rect(width="100%", height="100%", fill=fill)
text(x=20, y=50, font-size=36, font-weight="bold", fill=color) Build status: #{status}
if (message)
text(x=20, y=80, font-size=18, fill=color) #{message}

Loading…
Cancel
Save