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.
127 lines
3.0 KiB
127 lines
3.0 KiB
11 years ago
|
"use strict";
|
||
|
|
||
8 years ago
|
import * as _ from "underscore";
|
||
8 years ago
|
import { parse } from "url";
|
||
|
|
||
8 years ago
|
import { getReport } from "../status-processor";
|
||
11 years ago
|
|
||
8 years ago
|
const parseOptionsFromReferer = (path, callback) => {
|
||
8 years ago
|
const pathParts = path.split("/").filter((value) => value);
|
||
8 years ago
|
const [, secondPart, thirdPart] = pathParts;
|
||
9 years ago
|
|
||
8 years ago
|
if (!secondPart) {
|
||
8 years ago
|
return callback("BadRequest", {});
|
||
8 years ago
|
}
|
||
11 years ago
|
|
||
8 years ago
|
if (thirdPart === "tree") {
|
||
8 years ago
|
const [owner, reponame, , branchName, rev] = pathParts;
|
||
|
|
||
|
return callback(null, {
|
||
|
branchName,
|
||
|
owner,
|
||
|
reponame,
|
||
8 years ago
|
rev,
|
||
8 years ago
|
});
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
const [owner, reponame, branchName, rev] = pathParts;
|
||
|
|
||
|
return callback(null, {
|
||
|
branchName,
|
||
|
owner,
|
||
|
reponame,
|
||
8 years ago
|
rev,
|
||
8 years ago
|
});
|
||
11 years ago
|
};
|
||
|
|
||
8 years ago
|
const createShowReport = (res) => (err, inputOptions) => {
|
||
8 years ago
|
const options = {
|
||
|
...inputOptions || {},
|
||
|
err,
|
||
|
};
|
||
8 years ago
|
|
||
|
res.render("status", options);
|
||
8 years ago
|
};
|
||
9 years ago
|
|
||
8 years ago
|
export const image = (req, res) => {
|
||
8 years ago
|
const getAdditionalOptions = (err, options) => {
|
||
8 years ago
|
if (err === "ReportFileNotFound") {
|
||
8 years ago
|
return { status: "Building" };
|
||
8 years ago
|
}
|
||
|
|
||
|
if (err) {
|
||
|
return {
|
||
8 years ago
|
message: err,
|
||
|
status: "StatusError",
|
||
8 years ago
|
};
|
||
|
}
|
||
|
|
||
|
if (options.report.result === "MBSNotFound") {
|
||
8 years ago
|
return { status: "MBSNotUsed" };
|
||
8 years ago
|
}
|
||
|
|
||
|
if (options.report.err) {
|
||
|
return {
|
||
8 years ago
|
message: options.report.err,
|
||
|
status: "Error",
|
||
8 years ago
|
};
|
||
|
}
|
||
|
|
||
|
if ((options.report.result.warns.$allMessages || []).length) {
|
||
8 years ago
|
const [firstWarn] = options.report.result.warns.$allMessages;
|
||
|
|
||
8 years ago
|
return {
|
||
8 years ago
|
message: firstWarn.message,
|
||
|
status: "Warning",
|
||
8 years ago
|
};
|
||
|
}
|
||
|
|
||
|
const allInfos = options.report.result.infos.$allMessages || [];
|
||
|
|
||
|
if (allInfos.length) {
|
||
|
return {
|
||
8 years ago
|
message: allInfos[allInfos.length - 1].message,
|
||
|
status: "OK",
|
||
8 years ago
|
};
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return { status: "OK" };
|
||
8 years ago
|
};
|
||
|
|
||
|
const handle = (err, options) => {
|
||
8 years ago
|
res.setHeader("Content-Type", "image/svg+xml");
|
||
8 years ago
|
res.render("status-image", {
|
||
|
...options,
|
||
|
...getAdditionalOptions(err, options),
|
||
|
});
|
||
8 years ago
|
};
|
||
11 years ago
|
|
||
8 years ago
|
parseOptionsFromReferer(parse(req.headers.referer || "").pathname || "", (err, options) => {
|
||
8 years ago
|
if (err) {
|
||
|
return handle(err, options);
|
||
|
}
|
||
11 years ago
|
|
||
8 years ago
|
return getReport(req.app, options, handle);
|
||
8 years ago
|
});
|
||
11 years ago
|
};
|
||
|
|
||
8 years ago
|
export const page = (req, res) => {
|
||
8 years ago
|
const options = {
|
||
8 years ago
|
branch: `/refs/heads/${req.params.branch}`,
|
||
|
branchName: req.params.branch,
|
||
|
owner: req.params.owner,
|
||
|
reponame: req.params.reponame,
|
||
|
rev: req.params.rev,
|
||
8 years ago
|
};
|
||
11 years ago
|
|
||
8 years ago
|
getReport(req.app, options, createShowReport(res));
|
||
11 years ago
|
};
|
||
9 years ago
|
|
||
8 years ago
|
export const pageFromGithub = (req, res) => parseOptionsFromReferer(req.params[0], (err, options) => {
|
||
8 years ago
|
if (err) {
|
||
8 years ago
|
return createShowReport(res)(err, options);
|
||
8 years ago
|
}
|
||
9 years ago
|
|
||
8 years ago
|
return getReport(req.app, options, createShowReport(res));
|
||
8 years ago
|
});
|