52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
const express = require("express");
|
|
const { exec } = require("child_process");
|
|
const gradientBadge = require("gradient-badge");
|
|
const fs = require("fs");
|
|
|
|
const app = express();
|
|
const port = 3000;
|
|
const bodyParser = require("body-parser");
|
|
app.use(bodyParser.json());
|
|
app.post("/repo_change", (request, response) => {
|
|
var { body } = request;
|
|
exec(`git clone ${body.repository.clone_url}`, function (e, o, i) {
|
|
exec(`cd ${body.repository.name} && ls`, function (err, out, stderr) {
|
|
console.log(out)
|
|
exec(
|
|
`cd ${body.repository.name} && scc --format json --remap-all "":"Misc."`,
|
|
function (err, out, stderr) {
|
|
console.log(out)
|
|
const svgString = gradientBadge({
|
|
subject: "Lines of Code", // <text>
|
|
status: `${JSON.parse(out)[0].Lines}`, // <text>
|
|
gradient: ["0f8fff"], // array of colors (Hexadecimal or name)
|
|
});
|
|
fs.writeFile("output.svg", svgString, function (err) {
|
|
if (err) {
|
|
return console.log(err);
|
|
}
|
|
console.log("The file was saved!");
|
|
});
|
|
exec(`rm -rf ${body.repository.name}`)
|
|
exec(
|
|
`rm /var/www/html/badges/cloc/${body.repository.full_name}.svg`,
|
|
function (a, e, i) {
|
|
exec(
|
|
`mv output.svg /var/www/html/badges/cloc/${body.repository.full_name}.svg`
|
|
, function(err, o, oerr) {
|
|
console.log("Done")
|
|
});
|
|
}
|
|
);
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
response.end();
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Express api/webhook app listening at http://localhost:${port}`);
|
|
});
|