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/lib/routes/release.ts

52 lines
1.5 KiB

"use strict";
import { create as createArchiver } from "archiver";
8 years ago
import { join } from "path";
import { readReport } from "../report-processor";
const getDatePart = (report) => {
if (!report.date) {
return "unknowndate";
}
const date = new Date(report.date);
const paddingLeft = (str, paddingValue) => String(paddingValue + str).slice(-paddingValue.length);
const year = date.getFullYear();
const month = paddingLeft(date.getMonth() + 1, "00");
const day = paddingLeft(date.getDate(), "00");
const hours = paddingLeft(date.getHours(), "00");
const minutes = paddingLeft(date.getMinutes(), "00");
const seconds = paddingLeft(date.getSeconds(), "00");
return `${year}.${month}.${day}.${hours}.${minutes}.${seconds}`;
};
export default (req, res, next) => {
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,
};
const releasePath = join(req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev);
readReport(releasePath, (err, report) => {
if (err) {
return next(err);
}
const archive = createArchiver("zip");
archive.on("error", next);
res.attachment(`${options.reponame}.${getDatePart(report)}.${options.rev}.zip`, ".");
archive.pipe(res);
archive.directory(releasePath, false);
return archive.finalize();
});
};