aicommits 0.0.3 → 0.0.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 +18 -19
- package/aicommit.js +0 -2
- package/cli.js +6 -0
- package/lib.js +93 -0
- package/package.json +10 -15
package/README.md
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
# AI
|
|
1
|
+
# AI Commits - work in progress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AI Commits is a tool that writes your git commit messages for you. Never write a commit message again.
|
|
4
4
|
|
|
5
|
-
[](https://twitter.com/nutlope/status/1624646872890589184)
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Installation and usage
|
|
8
8
|
|
|
9
|
-
`npm install -g autocommit`
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
1. `npm install -g autocommit` to install the CLI
|
|
10
|
+
2. `export OPENAI_KEY=sk-xxxxxxxxxxxxxxxx` to specify your OpenAI API Key
|
|
11
|
+
3. `autocommit` after you run `git add .` to generate your commit
|
|
12
12
|
|
|
13
13
|
## How it works
|
|
14
14
|
|
|
15
|
-
This
|
|
15
|
+
This CLI tool runs a `git diff` command to grab all the latest changes, sends this to OpenAI's GPT-3, then returns the AI generated commit message. Video coming soon where I rebuild it from scratch to show you how to easily build your own CLI tools powered by AI.
|
|
16
|
+
|
|
17
|
+
## Limitations
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
It currently can only support git diffs of up to 200 lines of code. I'm working on version 2.0 which will be TypeScript-first, support conventional commits, and support long diffs.
|
|
18
20
|
|
|
19
21
|
## Remaining tasks
|
|
20
22
|
|
|
21
23
|
Now:
|
|
22
24
|
|
|
23
|
-
-
|
|
24
|
-
- [ ] Figure out how to fail gracefully instead of exit 1
|
|
25
|
-
- [ ] Try openai curie And/OR codex
|
|
26
|
-
|
|
27
|
-
After:
|
|
25
|
+
- Rewrite this in node to publish as an npm package
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
- [ ] Look into better conventional commit support, look at other CLIs
|
|
31
|
-
- [ ] Try supporting more than 200 lines by grabbing the diff per file
|
|
32
|
-
- [ ] Build landing page
|
|
27
|
+
Future tasks:
|
|
33
28
|
|
|
34
|
-
|
|
29
|
+
- Experiment with openai curie and/or codex
|
|
30
|
+
- Add conventional commit support
|
|
31
|
+
- Try supporting more than 200 lines by grabbing the diff per file
|
|
32
|
+
- Rewrite in TypeScript
|
|
33
|
+
- Build landing page for the 2.0 launch
|
package/aicommit.js
CHANGED
package/cli.js
ADDED
package/lib.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execSync, spawn } = require("child_process");
|
|
3
|
+
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
|
|
6
|
+
export async function main() {
|
|
7
|
+
console.log("Welcome to AICommit!");
|
|
8
|
+
if (!OPENAI_API_KEY) {
|
|
9
|
+
console.error(
|
|
10
|
+
"Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
|
|
11
|
+
);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
// Check to see if the user is in a git repo
|
|
15
|
+
try {
|
|
16
|
+
execSync("git rev-parse --is-inside-work-tree", {
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
stdio: "ignore",
|
|
19
|
+
});
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error("This is not a git repository");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let conventionalCommit = false;
|
|
26
|
+
|
|
27
|
+
const diff = execSync("git diff --cached", { encoding: "utf8" });
|
|
28
|
+
|
|
29
|
+
if (!diff) {
|
|
30
|
+
console.log(
|
|
31
|
+
"No staged changes found. Make sure there are changes and run `git add .`"
|
|
32
|
+
);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
|
37
|
+
if (diff.length > 8000) {
|
|
38
|
+
console.log("The diff is too large to write a commit message.");
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
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. ${
|
|
43
|
+
conventionalCommit
|
|
44
|
+
? "Preface the commit with 'feat:' if it is a feature or 'fix:' if it is a bug."
|
|
45
|
+
: "Do not preface the commit with anything."
|
|
46
|
+
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
|
47
|
+
|
|
48
|
+
const aiCommitMessage = await generateCommitMessage(prompt);
|
|
49
|
+
|
|
50
|
+
console.log(aiCommitMessage);
|
|
51
|
+
|
|
52
|
+
const confirmationMessage = await inquirer.prompt([
|
|
53
|
+
{
|
|
54
|
+
name: "useCommitMessage",
|
|
55
|
+
message: "Would you like to use this commit message? (Y / n)",
|
|
56
|
+
choices: ["Y", "y", "n"],
|
|
57
|
+
default: "y",
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
if (confirmationMessage !== "n") {
|
|
62
|
+
execSync(`git commit -m "${cleanedUpAiCommit}"`, {
|
|
63
|
+
encoding: "utf8",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function generateCommitMessage(prompt) {
|
|
69
|
+
const payload = {
|
|
70
|
+
model: "text-davinci-003",
|
|
71
|
+
prompt,
|
|
72
|
+
temperature: 0.7,
|
|
73
|
+
top_p: 1,
|
|
74
|
+
frequency_penalty: 0,
|
|
75
|
+
presence_penalty: 0,
|
|
76
|
+
max_tokens: 200,
|
|
77
|
+
stream: false,
|
|
78
|
+
n: 1,
|
|
79
|
+
};
|
|
80
|
+
const response = await fetch("https://api.openai.com/v1/completions", {
|
|
81
|
+
headers: {
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`,
|
|
84
|
+
},
|
|
85
|
+
method: "POST",
|
|
86
|
+
body: JSON.stringify(payload),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const json = await response.json();
|
|
90
|
+
const aiCommit = json.choices[0].text;
|
|
91
|
+
|
|
92
|
+
return aiCommit.replace(/(\r\n|\n|\r)/gm, "");
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicommits",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"start": "./aicommit.js"
|
|
9
|
-
},
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Writes your git commit messages for you with AI",
|
|
5
|
+
"main": "cli.js",
|
|
10
6
|
"bin": {
|
|
11
|
-
"gpt-commit": "./
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/Nutlope/ai-commit.git"
|
|
7
|
+
"gpt-commit": "./cli.js"
|
|
16
8
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
9
|
+
"repository": "https://github.com/Nutlope/aicommits",
|
|
10
|
+
"author": "Hassan El Mghari (@nutlope)",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"inquirer": "^9.1.4"
|
|
14
|
+
}
|
|
20
15
|
}
|