mirror of
https://github.com/imputnet/cobalt.git
synced 2025-12-12 05:29:54 +00:00
26 lines
836 B
JavaScript
26 lines
836 B
JavaScript
import { execSync } from "child_process";
|
|
|
|
let commit, commitInfo, branch;
|
|
|
|
export function shortCommit() {
|
|
if (commit) return commit;
|
|
if (process.env.GIT_COMMIT) return process.env.GIT_COMMIT;
|
|
let c = execSync('git rev-parse --short HEAD').toString().trim();
|
|
commit = c;
|
|
return c
|
|
}
|
|
export function getCommitInfo() {
|
|
if (commitInfo) return commitInfo;
|
|
let d = execSync(`git show -s --format='%s;;;%B'`).toString().trim().replace(/[\r\n]/gm, '\n').split(';;;');
|
|
d[1] = d[1].replace(d[0], '').trim().toString().replace(/[\r\n]/gm, '<br>');
|
|
commitInfo = d;
|
|
return d
|
|
}
|
|
export function getCurrentBranch() {
|
|
if (branch) return branch;
|
|
if (process.env.GIT_BRANCH) return process.env.GIT_BRANCH;
|
|
let b = execSync('git branch --show-current').toString().trim();
|
|
branch = b;
|
|
return b
|
|
}
|