first working version on npm! v0.1
This commit is contained in:
23
index.js
23
index.js
@@ -7,10 +7,11 @@ import fetch from "node-fetch";
|
|||||||
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("Welcome to AICommit!");
|
console.log("▲ Welcome to AICommit!");
|
||||||
|
|
||||||
if (!OPENAI_API_KEY) {
|
if (!OPENAI_API_KEY) {
|
||||||
console.error(
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -21,7 +22,7 @@ async function main() {
|
|||||||
stdio: "ignore",
|
stdio: "ignore",
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("This is not a git repository");
|
console.error("▲ This is not a git repository");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,14 +32,14 @@ async function main() {
|
|||||||
|
|
||||||
if (!diff) {
|
if (!diff) {
|
||||||
console.log(
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
||||||
if (diff.length > 8000) {
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ async function main() {
|
|||||||
: "Do not preface the commit with anything."
|
: "Do not preface the commit with anything."
|
||||||
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
||||||
|
|
||||||
|
console.log("▲ Generating your AI commit message...\n");
|
||||||
const aiCommitMessage = await generateCommitMessage(prompt);
|
const aiCommitMessage = await generateCommitMessage(prompt);
|
||||||
|
|
||||||
console.log(aiCommitMessage);
|
console.log(aiCommitMessage);
|
||||||
@@ -61,11 +63,16 @@ async function main() {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (confirmationMessage !== "n") {
|
console.log("Confirmation message is: ", confirmationMessage);
|
||||||
execSync(`git commit -m "${cleanedUpAiCommit}"`, {
|
|
||||||
|
if (confirmationMessage === "n") {
|
||||||
|
console.log("▲ Commit message has not been commited.`");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
execSync(`git commit -m "${aiCommitMessage}"`, {
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateCommitMessage(prompt) {
|
async function generateCommitMessage(prompt) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aicommits",
|
"name": "aicommits",
|
||||||
"version": "0.0.9",
|
"version": "0.1.0",
|
||||||
"description": "Writes your git commit messages for you with AI",
|
"description": "Writes your git commit messages for you with AI",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
Reference in New Issue
Block a user