39 lines
No EOL
975 B
TypeScript
39 lines
No EOL
975 B
TypeScript
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);
|
|
});
|
|
}
|
|
} |