From e7b46d548713775b203eac2a897aab87b0a4c02c Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:04:31 +0000 Subject: [PATCH 1/7] Add commit type and confirmation prompt for message generation --- aicommits.ts | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index fbd38e80..87cb8daf 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -52,13 +52,53 @@ export async function main() { let prompt = `I want you to act like a git commit message writer. I will input a git diff and your job is to convert it into a useful commit message. Do not preface the commit with anything, use the present tense, return a complete sentence, and do not repeat yourself: ${diff}`; + const commitTypeConfirmation = await inquirer.prompt([ + { + name: "useCommitTypeConfirmation", + message: "Would you like to add a commit type?", + choices: ["Y", "y", "n"], + default: "n", + }, + ]); + + let commitType: string | undefined; + + if (commitTypeConfirmation.useCommitTypeConfirmation !== "n") { + commitType = await inquirer.prompt([ + { + name: "commitType", + message: "What type commit is this?", + choices: [ + "Feat", + "Fix", + "Refactor", + "Chore", + "Docs", + "Style", + "Test", + "Perf", + "CI", + "Build", + "Revert", + ], + }, + ]); + } + console.log( chalk.white("▲ ") + chalk.gray("Generating your AI commit message...\n") ); const aiCommitMessage = await generateCommitMessage(prompt); - console.log( - chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage + "\n" + const commitMessage = !commitType + ? aiCommitMessage + : `${commitType}: ${aiCommitMessage}`; + + let commit = console.log( + chalk.white("▲ ") + + chalk.bold("Commit message: ") + + `${commitMessage}` + + "\n" ); const confirmationMessage = await inquirer.prompt([ @@ -75,7 +115,7 @@ export async function main() { process.exit(1); } - execSync(`git commit -m "${aiCommitMessage}"`, { + execSync(`git commit -m "${commitMessage}"`, { stdio: "inherit", encoding: "utf8", }); From 729552cdd6c85ad447aa032375bea8bf3e93a489 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:07:24 +0000 Subject: [PATCH 2/7] Update prompt to include 'y/n' option and add type list selection for commitType --- aicommits.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index 87cb8daf..c901f935 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -57,16 +57,17 @@ export async function main() { name: "useCommitTypeConfirmation", message: "Would you like to add a commit type?", choices: ["Y", "y", "n"], - default: "n", + default: "y/n", }, ]); let commitType: string | undefined; - + if (commitTypeConfirmation.useCommitTypeConfirmation !== "n") { commitType = await inquirer.prompt([ { name: "commitType", + type: "list", message: "What type commit is this?", choices: [ "Feat", @@ -82,7 +83,7 @@ export async function main() { "Revert", ], }, - ]); + ]).commitType; } console.log( From 8815c4adf4f0b2e85fe554a626b1e65c04ae8f91 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:08:38 +0000 Subject: [PATCH 3/7] Refactor confirmation prompt to include options for user input --- aicommits.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index c901f935..1560b304 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -55,9 +55,9 @@ export async function main() { const commitTypeConfirmation = await inquirer.prompt([ { name: "useCommitTypeConfirmation", - message: "Would you like to add a commit type?", + message: "Would you like to add a commit type? (Y / n)", choices: ["Y", "y", "n"], - default: "y/n", + default: "n", }, ]); @@ -95,7 +95,7 @@ export async function main() { ? aiCommitMessage : `${commitType}: ${aiCommitMessage}`; - let commit = console.log( + console.log( chalk.white("▲ ") + chalk.bold("Commit message: ") + `${commitMessage}` + From 3d950fa73336c10d0e46b3ac50e953a5f1a1e96a Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:10:36 +0000 Subject: [PATCH 4/7] undefined: Remove check for empty commit type and update condition to use strict comparison --- aicommits.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index 1560b304..1c2ac1c3 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -91,9 +91,8 @@ export async function main() { ); const aiCommitMessage = await generateCommitMessage(prompt); - const commitMessage = !commitType - ? aiCommitMessage - : `${commitType}: ${aiCommitMessage}`; + const commitMessage = + commitType === "n" ? aiCommitMessage : `${commitType}: ${aiCommitMessage}`; console.log( chalk.white("▲ ") + From 99f828f8d4e90e0185fc97f56aec99e37713bd5f Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:13:28 +0000 Subject: [PATCH 5/7] undefined: Update commit type field and console log commit type --- aicommits.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index 1c2ac1c3..57202d7f 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -66,7 +66,7 @@ export async function main() { if (commitTypeConfirmation.useCommitTypeConfirmation !== "n") { commitType = await inquirer.prompt([ { - name: "commitType", + name: "useCommitType", type: "list", message: "What type commit is this?", choices: [ @@ -83,7 +83,8 @@ export async function main() { "Revert", ], }, - ]).commitType; + ]).useCommitType; + console.log(commitType) } console.log( From 22149d6034cc01371176f9785634c7ab0fadde18 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:46:20 +0000 Subject: [PATCH 6/7] Feat: Update logic to include commit type confirmation when generating commit message. --- aicommits.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index 57202d7f..1bc6361a 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -57,7 +57,6 @@ export async function main() { name: "useCommitTypeConfirmation", message: "Would you like to add a commit type? (Y / n)", choices: ["Y", "y", "n"], - default: "n", }, ]); @@ -84,7 +83,7 @@ export async function main() { ], }, ]).useCommitType; - console.log(commitType) + console.log(commitType); } console.log( @@ -93,7 +92,9 @@ export async function main() { const aiCommitMessage = await generateCommitMessage(prompt); const commitMessage = - commitType === "n" ? aiCommitMessage : `${commitType}: ${aiCommitMessage}`; + commitTypeConfirmation.useCommitTypeConfirmation === "n" + ? aiCommitMessage + : `${commitType}: ${aiCommitMessage}`; console.log( chalk.white("▲ ") + From d4ec257564449a4cb9870431d83c653965eb65f5 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Tue, 14 Feb 2023 11:47:35 +0000 Subject: [PATCH 7/7] feat: add commit types as options --- aicommits.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/aicommits.ts b/aicommits.ts index 1bc6361a..9712c99f 100644 --- a/aicommits.ts +++ b/aicommits.ts @@ -60,9 +60,9 @@ export async function main() { }, ]); - let commitType: string | undefined; + let commitType; - if (commitTypeConfirmation.useCommitTypeConfirmation !== "n") { + if (commitTypeConfirmation.useCommitTypeConfirmation.toLowerCase() === "y") { commitType = await inquirer.prompt([ { name: "useCommitType", @@ -82,8 +82,7 @@ export async function main() { "Revert", ], }, - ]).useCommitType; - console.log(commitType); + ]); } console.log( @@ -94,7 +93,7 @@ export async function main() { const commitMessage = commitTypeConfirmation.useCommitTypeConfirmation === "n" ? aiCommitMessage - : `${commitType}: ${aiCommitMessage}`; + : `${commitType.useCommitType}: ${aiCommitMessage}`; console.log( chalk.white("▲ ") +