From fadac88799cb7a469a7f6fbf2b5a4bf27b54162f Mon Sep 17 00:00:00 2001 From: Hassan El Mghari Date: Mon, 13 Feb 2023 15:52:41 -0500 Subject: [PATCH] first working version on npm! v0.1 --- index.js | 25 ++++++++++++++++--------- package.json | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 9d7ece7..42a9c9b 100644 --- a/index.js +++ b/index.js @@ -7,10 +7,11 @@ import fetch from "node-fetch"; let OPENAI_API_KEY = process.env.OPENAI_API_KEY; async function main() { - console.log("Welcome to AICommit!"); + console.log("▲ Welcome to AICommit!"); + if (!OPENAI_API_KEY) { console.error( - "Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'" + "▲ Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'" ); process.exit(1); } @@ -21,7 +22,7 @@ async function main() { stdio: "ignore", }); } catch (e) { - console.error("This is not a git repository"); + console.error("▲ This is not a git repository"); process.exit(1); } @@ -31,14 +32,14 @@ async function main() { if (!diff) { console.log( - "No staged changes found. Make sure there are changes and run `git add .`" + "▲ No staged changes found. Make sure there are changes and run `git add .`" ); process.exit(1); } // Accounting for GPT-3's input req of 4k tokens (approx 8k chars) if (diff.length > 8000) { - console.log("The diff is too large to write a commit message."); + console.log("▲ The diff is too large to write a commit message."); process.exit(1); } @@ -48,6 +49,7 @@ async function main() { : "Do not preface the commit with anything." } Return a complete sentence and do not repeat yourself: ${diff}`; + console.log("▲ Generating your AI commit message...\n"); const aiCommitMessage = await generateCommitMessage(prompt); console.log(aiCommitMessage); @@ -61,11 +63,16 @@ async function main() { }, ]); - if (confirmationMessage !== "n") { - execSync(`git commit -m "${cleanedUpAiCommit}"`, { - encoding: "utf8", - }); + console.log("Confirmation message is: ", confirmationMessage); + + if (confirmationMessage === "n") { + console.log("▲ Commit message has not been commited.`"); + process.exit(1); } + + execSync(`git commit -m "${aiCommitMessage}"`, { + encoding: "utf8", + }); } async function generateCommitMessage(prompt) { diff --git a/package.json b/package.json index ff7d712..e485a28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aicommits", - "version": "0.0.9", + "version": "0.1.0", "description": "Writes your git commit messages for you with AI", "main": "index.js", "bin": {