From efc60effdcd5a6df58811c0b0c658b7fb7760cce Mon Sep 17 00:00:00 2001 From: Ramon Gebben Date: Mon, 23 Apr 2018 10:27:24 +0200 Subject: [PATCH] #15: Using short SHA's and showing commit messages --- lib/commands/review/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/commands/review/index.js b/lib/commands/review/index.js index aaaf44d..6dd534a 100644 --- a/lib/commands/review/index.js +++ b/lib/commands/review/index.js @@ -8,10 +8,14 @@ const { hasGit } = require('../../utils/hasGit'); const readDirAsync = promisify(readdir); -const getShas = () => new Promise((resolve) => { - const gitLog = exec('git log --format=format:%H'); +const getCommits = () => new Promise((resolve) => { + const gitLog = exec('git log --format=format:[%h]\\ %s -20'); gitLog.stdout.on('data', (data) => { - resolve(data.split('\n').filter(x => x !== '')); + const commits = data.split('\n') + .filter(x => x !== '') + .map(x => x.substr(0, 40).concat('...')); + + return resolve(commits); }); }); @@ -20,8 +24,8 @@ const review = async({ userId }) => { const files = await readDirAsync(currentWorkingDir); const itHasGit = hasGit(files); if (itHasGit) { - const shas = await getShas(); - const choices = ['HEAD^', ...shas]; + const commits = await getCommits(); + const choices = ['HEAD^', ...commits]; const { sha = 'HEAD^' } = inquirer.prompt([{ name: 'sha', message: 'From which commit do you want to review?',