From 20b19519c5b094eb7feab65cbba3ce5c6751331b Mon Sep 17 00:00:00 2001 From: IvanZidov Date: Tue, 23 May 2023 10:47:30 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(commit.ts):=20add=20option=20t?= =?UTF-8?q?o=20edit=20commit=20message=20before=20confirming=20it=20with?= =?UTF-8?q?=20the=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/commit.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index b6c337be..413aa1f5 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -16,7 +16,8 @@ import { isCancel, intro, multiselect, - select + select, + text } from '@clack/prompts'; import chalk from 'chalk'; import { trytm } from '../utils/trytm'; @@ -35,7 +36,7 @@ const generateCommitMessageFromGitDiff = async ( const commitSpinner = spinner(); commitSpinner.start('Generating the commit message'); try { - const commitMessage = await generateCommitMessageByDiff(diff); + let commitMessage = await generateCommitMessageByDiff(diff); commitSpinner.stop('📝 Commit message generated'); @@ -46,11 +47,23 @@ ${commitMessage} ${chalk.grey('——————————————————')}` ); - const isCommitConfirmedByUser = await confirm({ - message: 'Confirm the commit message?' + const userAction = await select({ + message: 'Confirm the commit message?', + options: [ + { value: 'Yes', label: 'Yes' }, + { value: 'No', label: 'No' }, + { value: 'Edit', label: 'Edit' } + ] }); - if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) { + if (userAction === 'Edit') { + commitMessage = await text({ + message: 'Please edit the commit message:', + initialValue: commitMessage + }); + } + + if (userAction === 'Yes' || userAction === 'Edit') { const { stdout } = await execa('git', [ 'commit', '-m',