aicommits 0.1.1 → 0.1.4

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/README.md CHANGED
@@ -25,6 +25,7 @@ Now:
25
25
  - Rewrite this in node to publish as an npm package
26
26
  - Fix screenshot on npm
27
27
  - add an npm ignore and add demo to README as well
28
+ - make CLI looks nicer
28
29
 
29
30
  Future tasks:
30
31
 
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import chalk from "chalk";
3
4
  import { execSync } from "child_process";
4
5
  import inquirer from "inquirer";
5
6
  import fetch from "node-fetch";
@@ -7,11 +8,12 @@ import fetch from "node-fetch";
7
8
  let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
8
9
 
9
10
  async function main() {
10
- console.log("▲ Welcome to AICommit!");
11
+ console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
11
12
 
12
13
  if (!OPENAI_API_KEY) {
13
14
  console.error(
14
- "▲ Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
15
+ chalk.white("▲ ") +
16
+ "Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
15
17
  );
16
18
  process.exit(1);
17
19
  }
@@ -21,37 +23,38 @@ async function main() {
21
23
  stdio: "ignore",
22
24
  });
23
25
  } catch (e) {
24
- console.error("▲ This is not a git repository");
26
+ console.error(chalk.white("▲ ") + "This is not a git repository");
25
27
  process.exit(1);
26
28
  }
27
29
 
28
- let conventionalCommit = false;
29
-
30
30
  const diff = execSync("git diff --cached", { encoding: "utf8" });
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
+ chalk.white("▲ ") +
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(
43
+ chalk.white("▲ ") + "The diff is too large to write a commit message."
44
+ );
42
45
  process.exit(1);
43
46
  }
44
47
 
45
- let prompt = `I want you to act like a git commit message writer. I will input a git diff and your job is to convert it into a useful commit message. ${
46
- conventionalCommit
47
- ? "Preface the commit with 'feat:' if it is a feature or 'fix:' if it is a bug."
48
- : "Do not preface the commit with anything."
49
- } Return a complete sentence and do not repeat yourself: ${diff}`;
48
+ let prompt = `I want you to act like a git commit message writer. I will input a git diff and your job is to convert it into a useful commit message. Do not preface the commit with anything, return a complete sentence, and do not repeat yourself: ${diff}`;
50
49
 
51
- console.log("▲ Generating your AI commit message...\n");
50
+ console.log(
51
+ chalk.white("▲ ") + chalk.gray("Generating your AI commit message...\n")
52
+ );
52
53
  const aiCommitMessage = await generateCommitMessage(prompt);
53
54
 
54
- console.log(aiCommitMessage);
55
+ console.log(
56
+ chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage + "\n"
57
+ );
55
58
 
56
59
  const confirmationMessage = await inquirer.prompt([
57
60
  {
@@ -63,7 +66,7 @@ async function main() {
63
66
  ]);
64
67
 
65
68
  if (confirmationMessage.useCommitMessage === "n") {
66
- console.log("▲ Commit message has not been commited.`");
69
+ console.log(chalk.white("▲ ") + "Commit message has not been commited.");
67
70
  process.exit(1);
68
71
  }
69
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicommits",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
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
+ "chalk": "^5.2.0",
14
15
  "inquirer": "^9.1.4",
15
16
  "node-fetch": "^3.3.0"
16
17
  }
package/aicommit.js DELETED
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env zx
2
-
3
- void (async function () {
4
- $.verbose = false;
5
-
6
- let conventionalCommit = false;
7
-
8
- console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
9
-
10
- let pwd = await $`cd ~ && pwd;`;
11
-
12
- let { OPENAI_API_KEY } = await fs.readJson(
13
- `${pwd.stdout.trim()}/ai-commit/.env.json`
14
- );
15
- let diff = await $`git diff --cached`;
16
-
17
- // Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
18
- if (diff.stdout.length > 8000) {
19
- console.log("The diff is too large to write a commit message.");
20
- await $`exit 1`;
21
- }
22
-
23
- if (diff.stdout.length === 0) {
24
- console.log(
25
- "No staged changes found. Make sure there are changes and run `git add .`"
26
- );
27
- await $`exit 1`;
28
- }
29
-
30
- let prompt = `I want you to act like a git commit message writer. I will input a git diff and your job is to convert it into a useful commit message. ${
31
- conventionalCommit
32
- ? "Preface the commit with 'feat:' if it is a feature or 'fix:' if it is a bug."
33
- : "Do not preface the commit with anything."
34
- } Return a complete sentence and do not repeat yourself: ${diff}`;
35
-
36
- const payload = {
37
- model: "text-davinci-003",
38
- prompt,
39
- temperature: 0.7,
40
- top_p: 1,
41
- frequency_penalty: 0,
42
- presence_penalty: 0,
43
- max_tokens: 200,
44
- stream: false,
45
- n: 1,
46
- };
47
-
48
- console.log(
49
- chalk.white("▲ ") + chalk.gray("Generating your AI commit message...")
50
- );
51
-
52
- const response = await fetch("https://api.openai.com/v1/completions", {
53
- headers: {
54
- "Content-Type": "application/json",
55
- Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`,
56
- },
57
- method: "POST",
58
- body: JSON.stringify(payload),
59
- });
60
-
61
- const json = await response.json();
62
- const aiCommit = json.choices[0].text;
63
- let cleanedUpAiCommit = aiCommit.replace(/(\r\n|\n|\r)/gm, "");
64
-
65
- echo(cleanedUpAiCommit);
66
-
67
- let confirmationMessage = await question(
68
- "\nWould you like to use this commit message? " + chalk.yellow("(Y/n) "),
69
- {
70
- choices: ["Y", "n"],
71
- }
72
- );
73
-
74
- $.verbose = true;
75
- echo("\n");
76
-
77
- if (confirmationMessage !== "n") {
78
- await $`git commit -m ${cleanedUpAiCommit}`;
79
- }
80
- })();