aicommits 0.0.8 → 0.1.0

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.
Files changed (2) hide show
  1. package/index.js +16 -9
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -7,10 +7,11 @@ 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
  }
@@ -21,7 +22,7 @@ async function main() {
21
22
  stdio: "ignore",
22
23
  });
23
24
  } catch (e) {
24
- console.error("This is not a git repository");
25
+ console.error("This is not a git repository");
25
26
  process.exit(1);
26
27
  }
27
28
 
@@ -31,14 +32,14 @@ async function main() {
31
32
 
32
33
  if (!diff) {
33
34
  console.log(
34
- "No staged changes found. Make sure there are changes and run `git add .`"
35
+ "No staged changes found. Make sure there are changes and run `git add .`"
35
36
  );
36
37
  process.exit(1);
37
38
  }
38
39
 
39
40
  // Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
40
41
  if (diff.length > 8000) {
41
- console.log("The diff is too large to write a commit message.");
42
+ console.log("The diff is too large to write a commit message.");
42
43
  process.exit(1);
43
44
  }
44
45
 
@@ -48,6 +49,7 @@ async function main() {
48
49
  : "Do not preface the commit with anything."
49
50
  } Return a complete sentence and do not repeat yourself: ${diff}`;
50
51
 
52
+ console.log("▲ Generating your AI commit message...\n");
51
53
  const aiCommitMessage = await generateCommitMessage(prompt);
52
54
 
53
55
  console.log(aiCommitMessage);
@@ -61,11 +63,16 @@ async function main() {
61
63
  },
62
64
  ]);
63
65
 
64
- if (confirmationMessage !== "n") {
65
- execSync(`git commit -m "${cleanedUpAiCommit}"`, {
66
- encoding: "utf8",
67
- });
66
+ console.log("Confirmation message is: ", confirmationMessage);
67
+
68
+ if (confirmationMessage === "n") {
69
+ console.log("▲ Commit message has not been commited.`");
70
+ process.exit(1);
68
71
  }
72
+
73
+ execSync(`git commit -m "${aiCommitMessage}"`, {
74
+ encoding: "utf8",
75
+ });
69
76
  }
70
77
 
71
78
  async function generateCommitMessage(prompt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicommits",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "Writes your git commit messages for you with AI",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  "author": "Hassan El Mghari (@nutlope)",
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
- "inquirer": "^9.1.4"
14
+ "inquirer": "^9.1.4",
15
+ "node-fetch": "^3.3.0"
15
16
  }
16
17
  }