added colors and spaces
This commit is contained in:
26
index.js
26
index.js
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import chalk from "chalk";
|
||||
import { execSync } from "child_process";
|
||||
import inquirer from "inquirer";
|
||||
import fetch from "node-fetch";
|
||||
@@ -7,11 +8,12 @@ import fetch from "node-fetch";
|
||||
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||
|
||||
async function main() {
|
||||
console.log("▲ Welcome to AICommit!");
|
||||
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
|
||||
|
||||
if (!OPENAI_API_KEY) {
|
||||
console.error(
|
||||
"▲ Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
|
||||
chalk.white("▲ ") +
|
||||
"Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -21,7 +23,7 @@ async function main() {
|
||||
stdio: "ignore",
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("▲ This is not a git repository");
|
||||
console.error(chalk.white("▲ ") + "This is not a git repository");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -31,14 +33,17 @@ async function main() {
|
||||
|
||||
if (!diff) {
|
||||
console.log(
|
||||
"▲ No staged changes found. Make sure there are changes and run `git add .`"
|
||||
chalk.white("▲ ") +
|
||||
"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(
|
||||
chalk.white("▲ ") + "The diff is too large to write a commit message."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -48,10 +53,15 @@ 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");
|
||||
console.log(
|
||||
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...\n")
|
||||
);
|
||||
const aiCommitMessage = await generateCommitMessage(prompt);
|
||||
|
||||
console.log(aiCommitMessage);
|
||||
console.log(
|
||||
chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage
|
||||
);
|
||||
console.log("\n");
|
||||
|
||||
const confirmationMessage = await inquirer.prompt([
|
||||
{
|
||||
@@ -63,7 +73,7 @@ async function main() {
|
||||
]);
|
||||
|
||||
if (confirmationMessage.useCommitMessage === "n") {
|
||||
console.log("▲ Commit message has not been commited.`");
|
||||
console.log(chalk.white("▲ ") + "Commit message has not been commited.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user