Sharkey/src/utils/lastCommitInfo.ts

22 lines
875 B
TypeScript
Raw Normal View History

2016-12-30 20:29:24 +02:00
import Logger from './logger';
import * as chalk from 'chalk';
2017-01-02 23:03:19 +02:00
import prominence = require('prominence');
import git = require('git-last-commit');
2016-12-30 20:29:24 +02:00
2017-01-02 21:39:44 +02:00
export default class {
2016-12-30 20:29:24 +02:00
static async show(): Promise<void> {
let logger = new Logger('LastCommit');
try {
const commit = await prominence(git).getLastCommit();
const shortHash: string = commit.shortHash;
const hash: string = commit.hash;
const commitDate = new Date(parseInt(commit.committedOn, 10) * 1000).toLocaleDateString('ja-JP');
const commitTime = new Date(parseInt(commit.committedOn, 10) * 1000).toLocaleTimeString('ja-JP');
logger.info(`${shortHash}${chalk.gray(hash.substr(shortHash.length))}`);
logger.info(`${commit.subject} ${chalk.green(`(${commitDate} ${commitTime})`)} ${chalk.blue(`<${commit.author.name}>`)}`);
} catch (e) {
logger.info('No commit information found');
}
}
}