show git revision

This commit is contained in:
Archeb
2024-07-11 13:20:46 +08:00
parent a00042b848
commit 9d649f16e7
2 changed files with 57 additions and 36 deletions
+13 -1
View File
@@ -1,6 +1,18 @@
import * as docx from "docx";
import cookie from "cookie";
import fs from "fs";
import { execSync } from "child_process";
function getGitRevision() {
// get git revision and branch
try {
const revision = execSync("git rev-parse --short HEAD").toString().trim();
const branch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
return { revision, branch };
} catch (e) {
return { revision: "unknown", branch: "unknown" };
}
}
function createDirectoryIfNotExists(dirPath) {
if (!fs.existsSync(dirPath)) {
@@ -97,4 +109,4 @@ function createEvent(event, data) {
return `event: ${event}\ndata: ${data}\n\n`;
}
export { createEvent, createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie, createDocx };
export { createEvent, createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie, createDocx, getGitRevision };