Adds some more polish

This commit is contained in:
Michel Fedde 2025-06-26 21:38:03 +02:00
parent b3d0b3a90c
commit 11bd836ec3
18 changed files with 272 additions and 29 deletions

View file

@ -0,0 +1,39 @@
import * as fs from "node:fs";
import {Nullable} from "../types/Nullable";
import {DataManager} from "discord.js";
import * as util from "node:util";
export type BuildContext = {
target: string,
commitHash: string,
commitLink: string,
label: string,
}
export class BuildContextGetter {
private static EXPECTED_PATHS = [
"./deploy.json",
"./dist/deploy.json"
];
private static GIT_PATH = "https://git.iedsoftworks.com/neintonine/pnp-scheduler/commit/%s";
getContext(): Nullable<BuildContext> {
const path = this.findValidPath();
if (!path) {
return null;
}
const jsonData = fs.readFileSync(path).toString();
const data = JSON.parse(jsonData);
return {
...data,
commitLink: util.format(BuildContextGetter.GIT_PATH, data.commitHash)
}
}
private findValidPath(): Nullable<string> {
return BuildContextGetter.EXPECTED_PATHS.find((path) => {
return fs.existsSync(path);
});
}
}