Build server prototype (integration with GitHub / NuGet / etc)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
micro-build-server/BuildServer/routes/status.js

93 lines
2.4 KiB

"use strict";
var fs = require('fs'),
url = require('url'),
glob = require('glob'),
statusProcessor = require('../lib/status-processor');
var parseOptionsFromReferer = function (path, callback) {
var pathParts = path.split("/").filter(function (value) { return value; });
var result = {};
if (pathParts.length < 2) {
return callback("BadRequest", result);
}
if (pathParts[2] == "tree") {
pathParts.splice(2, 1);
}
result.owner = pathParts[0];
result.reponame = pathParts[1];
result.branchName = pathParts[2];
result.rev = pathParts[3];
return callback(null, result);
};
var createShowReport = function (res) {
return function (err, options) {
options = options || {};
options.err = err;
res.render('status', options);
}
}
exports.image = function(req, res) {
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";
11 years ago
options.message = options.report.result.warns.$allMessages[0].message;
} else {
options.status = "OK";
11 years ago
if ((options.report.result.infos.$allMessages || []).length > 0) {
options.message = options.report.result.infos.$allMessages[options.report.result.infos.$allMessages.length-1].message;
}
}
res.setHeader('Content-Type', 'image/svg+xml');
res.render('status-image', options);
};
parseOptionsFromReferer(url.parse(req.headers.referer || "").pathname || "", function (err, options) {
if (err) {
return handle(err, options);
}
statusProcessor.getReport(req.app, options, function (err, options) {
handle(err, options);
});
});
};
exports.page = function(req, res) {
var options = {
owner: req.params.owner,
reponame: req.params.reponame,
branchName: req.params.branch,
branch: "/refs/heads/" + req.params.branch,
rev: req.params.rev
};
statusProcessor.getReport(req.app, options, createShowReport(res));
};
exports.pageFromGithub = function (req, res) {
parseOptionsFromReferer(req.params[0], function (err, options) {
if (err) {
return showReport(err, options);
}
return statusProcessor.getReport(req.app, options, createShowReport(res));
});
}