Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(commit.ts): add option to edit commit message before confirmin… #179

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
isCancel,
intro,
multiselect,
select
select,
text
} from '@clack/prompts';
import chalk from 'chalk';
import { trytm } from '../utils/trytm';
Expand All @@ -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');

Expand All @@ -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',
Expand Down