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

Add commit type #17

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
45 changes: 43 additions & 2 deletions aicommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,54 @@ 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? (Y / n)",
choices: ["Y", "y", "n"],
},
]);

let commitType;

if (commitTypeConfirmation.useCommitTypeConfirmation.toLowerCase() === "y") {
commitType = await inquirer.prompt([
{
name: "useCommitType",
type: "list",
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);

const commitMessage =
commitTypeConfirmation.useCommitTypeConfirmation === "n"
? aiCommitMessage
: `${commitType.useCommitType}: ${aiCommitMessage}`;

console.log(
chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage + "\n"
chalk.white("▲ ") +
chalk.bold("Commit message: ") +
`${commitMessage}` +
"\n"
);

const confirmationMessage = await inquirer.prompt([
Expand All @@ -75,7 +116,7 @@ export async function main() {
process.exit(1);
}

execSync(`git commit -m "${aiCommitMessage}"`, {
execSync(`git commit -m "${commitMessage}"`, {
stdio: "inherit",
encoding: "utf8",
});
Expand Down