Implemented artifacts list; commit status URLs supported

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 9ded7ae76e
commit 9d462f7299
  1. 3
      BuildServer/app.js
  2. 81
      BuildServer/routes/status.js

@ -40,8 +40,9 @@ 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/:owner/:reponame/:branch/:rev', routes.status.page); app.get('/status/:owner/:reponame/:branch/:rev?', routes.status.page);
app.get('/status.svg', routes.status.image); app.get('/status.svg', routes.status.image);
app.get('/artifact/:owner/:reponame/:branch/:rev/:file', routes.artifact);
http.createServer(app).listen(app.get('port'), function(){ http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port')); console.log('Express server listening on port ' + app.get('port'));

@ -3,53 +3,68 @@
var fs = require('fs'), var fs = require('fs'),
url = require('url'); url = require('url');
var parseOptionsFromReferer = function (req, callback) { var addBranchInfo = function (app, options, callback) {
var pathParts = (url.parse(req.headers.referer || "").pathname || "").split("/"); var branchFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/$revs/" + options.rev + ".branch";
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) { fs.exists(branchFile, function (exists) {
if (!exists) { if (!exists) {
return callback("BranchFileNotFound", result); return callback("BranchFileNotFound", options);
} }
fs.readFile(branchFile, function (err, data) { fs.readFile(branchFile, function (err, data) {
if (err) { if (err) {
return callback(err, result); return callback(err, result);
} }
result.branch = data.toString(); options.branch = data.toString();
result.branchName = result.branch.split("/").pop(); options.branchName = options.branch.split("/").pop();
return callback(null, result); return callback(null, options);
}); });
}); });
} else { };
result.branchName = pathParts[4] || "master";
result.branch = "refs/heads/" + result.branchName; var addRevInfo = function (app, options, callback) {
// console.log(result); var revFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/latest.id";
var revFile = req.app.get('releasepath') + "/" + result.owner + "/" + result.reponame + "/" + result.branch + "/latest.id";
fs.exists(revFile, function (exists) { fs.exists(revFile, function (exists) {
if (!exists) { if (!exists) {
return callback("RevFileNotFound", result); return callback("RevFileNotFound", options);
} }
fs.readFile(revFile, function (err, data) { fs.readFile(revFile, function (err, data) {
if (err) { if (err) {
return callback(err, result); return callback(err, options);
} }
result.rev = data.toString(); options.rev = data.toString();
return callback(null, result); return callback(null, options);
}); });
}); });
};
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];
return addBranchInfo(req.app, result, callback);
} else {
result.branchName = pathParts[4] || "master";
result.branch = "refs/heads/" + result.branchName;
return addRevInfo(req.app, result, callback);
} }
}; };
var loadReport = function (app, options, callback) { var loadReport = function (app, options, callback) {
var reportFile = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev + "/report.json"; var releaseDir = app.get('releasepath') + "/" + options.owner + "/" + options.reponame + "/" + options.branch + "/" + options.rev;
fs.readdir(releaseDir, function (err, files) {
if (err) {
return callback(err, options);
}
var reportFile = reportFile = releaseDir + "/report.json";
options.files = files;
fs.exists(reportFile, function (exists) { fs.exists(reportFile, function (exists) {
if (!exists) { if (!exists) {
return callback("ReportFileNotFound", options); return callback("ReportFileNotFound", options);
@ -67,10 +82,11 @@ var loadReport = function (app, options, callback) {
return callback(null, options); return callback(null, options);
}); });
}); });
});
}; };
exports.image = function(req, res) { exports.image = function(req, res) {
// console.log(req.headers); console.log(req.headers);
var handle = function (err, options) { var handle = function (err, options) {
if (err === "ReportFileNotFound") { if (err === "ReportFileNotFound") {
options.status = "Building"; options.status = "Building";
@ -116,9 +132,20 @@ exports.page = function(req, res) {
branch: "/refs/heads/" + req.params.branch, branch: "/refs/heads/" + req.params.branch,
rev: req.params.rev rev: req.params.rev
}; };
var finish = function (err, options) {
loadReport(req.app, options, function (err, options) { loadReport(req.app, options, function (err, options) {
options.err = err; options.err = err;
console.log(options); console.log(options);
res.render('status', options); res.render('status', options);
}); });
}; };
if (/^[\da-f]{40}$/i.test(options.branchName)) {
options.rev = options.branchName;
options.branchName = undefined;
options.branch = undefined;
return addBranchInfo(req.app, options, finish);
} else {
return finish(undefined, options);
}
};

Loading…
Cancel
Save