aicommits 0.0.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,21 +7,21 @@ import fetch from "node-fetch";
|
|
|
7
7
|
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
8
8
|
|
|
9
9
|
async function main() {
|
|
10
|
-
console.log("Welcome to AICommit!");
|
|
10
|
+
console.log("▲ Welcome to AICommit!");
|
|
11
|
+
|
|
11
12
|
if (!OPENAI_API_KEY) {
|
|
12
13
|
console.error(
|
|
13
|
-
"Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
|
|
14
|
+
"▲ Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
|
|
14
15
|
);
|
|
15
16
|
process.exit(1);
|
|
16
17
|
}
|
|
17
|
-
// Check to see if the user is in a git repo
|
|
18
18
|
try {
|
|
19
19
|
execSync("git rev-parse --is-inside-work-tree", {
|
|
20
20
|
encoding: "utf8",
|
|
21
21
|
stdio: "ignore",
|
|
22
22
|
});
|
|
23
23
|
} catch (e) {
|
|
24
|
-
console.error("This is not a git repository");
|
|
24
|
+
console.error("▲ This is not a git repository");
|
|
25
25
|
process.exit(1);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -31,14 +31,14 @@ async function main() {
|
|
|
31
31
|
|
|
32
32
|
if (!diff) {
|
|
33
33
|
console.log(
|
|
34
|
-
"No staged changes found. Make sure there are changes and run `git add .`"
|
|
34
|
+
"▲ No staged changes found. Make sure there are changes and run `git add .`"
|
|
35
35
|
);
|
|
36
36
|
process.exit(1);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
|
40
40
|
if (diff.length > 8000) {
|
|
41
|
-
console.log("The diff is too large to write a commit message.");
|
|
41
|
+
console.log("▲ The diff is too large to write a commit message.");
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -48,6 +48,7 @@ async function main() {
|
|
|
48
48
|
: "Do not preface the commit with anything."
|
|
49
49
|
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
|
50
50
|
|
|
51
|
+
console.log("▲ Generating your AI commit message...\n");
|
|
51
52
|
const aiCommitMessage = await generateCommitMessage(prompt);
|
|
52
53
|
|
|
53
54
|
console.log(aiCommitMessage);
|
|
@@ -61,11 +62,15 @@ async function main() {
|
|
|
61
62
|
},
|
|
62
63
|
]);
|
|
63
64
|
|
|
64
|
-
if (confirmationMessage
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
65
|
+
if (confirmationMessage.useCommitMessage === "n") {
|
|
66
|
+
console.log("▲ Commit message has not been commited.`");
|
|
67
|
+
process.exit(1);
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
execSync(`git commit -m "${aiCommitMessage}"`, {
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
encoding: "utf8",
|
|
73
|
+
});
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
async function generateCommitMessage(prompt) {
|