UNPKG

@k8ts/instruments

Version:

A collection of utilities and core components for k8ts.

46 lines 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitTrace = void 0; const dayjs_1 = __importDefault(require("dayjs")); const simple_git_1 = __importDefault(require("simple-git")); class GitTrace { props; constructor(props) { this.props = props; } get text() { const hashPart = this.props.commit.sha.slice(0, 7); const shortDate = (0, dayjs_1.default)(this.props.commit.date).format("YYYY-MM-DD"); const shortMessage = this.props.commit.message.split("\n")[0].slice(0, 20); const author = this.props.commit.author; return `${hashPart} '${shortMessage}⋯' (${author}@${shortDate})`; } static async make(options) { options = { cwd: ".", absolute: false, ...options }; const sg = (0, simple_git_1.default)(options.cwd); const isRepo = await sg.checkIsRepo(); if (!isRepo) { return undefined; } const l = await sg.log({ maxCount: 1 }); return new GitTrace({ commit: { sha: l.latest.hash, message: l.latest.message, author: l.latest.author_name, date: l.latest.date } }); } } exports.GitTrace = GitTrace; //# sourceMappingURL=git.js.map