working v1
This commit is contained in:
16
aicommit.mjs
16
aicommit.mjs
@@ -1,12 +1,17 @@
|
||||
#!/usr/bin/env zx
|
||||
$.verbose = false;
|
||||
|
||||
// Add console.log with "no git diff"
|
||||
|
||||
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
|
||||
|
||||
let { OPENAI_API_KEY } = await fs.readJson("./.env.json");
|
||||
|
||||
let { OPENAI_API_KEY } = await fs.readJson(
|
||||
"/Users/hassan/dev/ai-commit/.env.json"
|
||||
);
|
||||
let diff = await quiet($`git diff --cached`);
|
||||
let prompt = `Write one detailed commit message based on the following commit. Do not preface the commit with anything, write it right away: ${diff}`;
|
||||
|
||||
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, do not repeat yourself, and return a complete sentence: ${diff}`;
|
||||
// let prompt = `Write one detailed commit message based on the following commit. Do not preface the commit with anything, write it right away: `;
|
||||
|
||||
const payload = {
|
||||
model: "text-davinci-003",
|
||||
@@ -21,7 +26,7 @@ const payload = {
|
||||
};
|
||||
|
||||
console.log(
|
||||
chalk.white("▲ ") + chalk.black("Generating your AI commit message...")
|
||||
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...")
|
||||
);
|
||||
|
||||
const response = await fetch("https://api.openai.com/v1/completions", {
|
||||
@@ -40,13 +45,14 @@ let cleanedUpAiCommit = aiCommit.replace(/(\r\n|\n|\r)/gm, "");
|
||||
echo(cleanedUpAiCommit);
|
||||
|
||||
let confirmationMessage = await question(
|
||||
"\nWould you like to use this commit message? " + chalk.yellow("(Y/n) \n"),
|
||||
"\nWould you like to use this commit message? " + chalk.yellow("(Y/n) "),
|
||||
{
|
||||
choices: ["Y", "n"],
|
||||
}
|
||||
);
|
||||
|
||||
$.verbose = true;
|
||||
echo("\n");
|
||||
|
||||
if (confirmationMessage !== "n") {
|
||||
await $`git commit -m ${cleanedUpAiCommit}`;
|
||||
|
||||
Reference in New Issue
Block a user