Initial
/ A job to count the lines of code. (push) Successful in 26s

This commit is contained in:
2023-10-07 04:17:20 +00:00
parent 299f5fe350
commit ce8091eeaf
6 changed files with 88 additions and 18 deletions
Submodule Gitea-Badge-Creator added at 299f5fe350
-5
View File
@@ -1,5 +0,0 @@
## Gitea-Badge-Creator ##
[![](https://drone.nicholaspease.com/api/badges/npease/Gitea-Badge-Creator/status.svg)](https://drone.nicholaspease.com/npease/Gitea-Badge-Creator)
[![](https://wakaapi.nicholaspease.com/api/badge/LAX18/interval:any/project:Gitea-Badge-Creator)](https://wakaapi.nicholaspease.com/summary?interval=any&project=Gitea-Badge-Creator)
![](https://gitea.nicholaspease.com/api/packages/npease/generic/cloc-Gitea-Badge-Creator/latest/cloc.png)
+20
View File
@@ -0,0 +1,20 @@
<svg width="122.7" height="20" viewBox="0 0 1227 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Lines of Code: 1720">
<title>Lines of Code: 1720</title>
<linearGradient id="hnzcl" x2="0" y2="100%">
<stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="WrfCH"><rect width="1227" height="200" rx="30" fill="#FFF"/></mask>
<g mask="url(#WrfCH)">
<rect width="847" height="200" fill="#555"/>
<rect width="380" height="200" fill="#0f8fff" x="847"/>
<rect width="1227" height="200" fill="url(#hnzcl)"/>
</g>
<g aria-hidden="true" fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
<text x="60" y="148" textLength="747" fill="#000" opacity="0.25">Lines of Code</text>
<text x="50" y="138" textLength="747">Lines of Code</text>
<text x="902" y="148" textLength="280" fill="#000" opacity="0.25">1720</text>
<text x="892" y="138" textLength="280">1720</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+21 -1
View File
@@ -5,7 +5,9 @@
"packages": {
"": {
"dependencies": {
"express": "^4.18.2"
"child_process": "^1.0.2",
"express": "^4.18.2",
"gradient-badge": "^1.3.1"
}
},
"node_modules/accepts": {
@@ -25,6 +27,11 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
},
"node_modules/badgen": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/badgen/-/badgen-3.2.3.tgz",
"integrity": "sha512-svDuwkc63E/z0ky3drpUppB83s/nlgDciH9m+STwwQoWyq7yCgew1qEfJ+9axkKdNq7MskByptWUN9j1PGMwFA=="
},
"node_modules/body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
@@ -68,6 +75,11 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/child_process": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz",
"integrity": "sha512-Wmza/JzL0SiWz7kl6MhIKT5ceIlnFPJX+lwUGj7Clhy5MMldsSoJR0+uvRzOS5Kv45Mq7t1PoE8TsOA9bzvb6g=="
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
@@ -244,6 +256,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/gradient-badge": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/gradient-badge/-/gradient-badge-1.3.1.tgz",
"integrity": "sha512-OvTFHZJSQ+fR7zWl6xz5PvniAfKRsHBy98NZ+kAWOnfmP27lt8wMA4oUvsQp0ppNET+2qE0oEnna2s3SiiqaVA==",
"dependencies": {
"badgen": "^3.2.1"
}
},
"node_modules/has": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz",
+3 -1
View File
@@ -1,5 +1,7 @@
{
"dependencies": {
"express": "^4.18.2"
"child_process": "^1.0.2",
"express": "^4.18.2",
"gradient-badge": "^1.3.1"
}
}
+43 -11
View File
@@ -1,15 +1,47 @@
const express = require('express');
const express = require("express");
const { exec } = require("child_process");
const gradientBadge = require("gradient-badge");
const fs = require("fs");
const app = express();
app.use(express.json());
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log("Server Listening on PORT:", PORT);
});
const port = 3000;
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.post("/repo_change", (request, response) => {
console.log(response)
response.send(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) {
exec(
'scc --format json --remap-all "":"Misc."',
function (err, out, stderr) {
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(`cd ../ && 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`
);
}
);
}
);
});
});
response.end();
});
app.listen(port, () => {
console.log(`Express api/webhook app listening at http://localhost:${port}`);
});