aicommits 0.1.2 → 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/index.js +2 -9
- package/package.json +1 -1
- package/aicommit.js +0 -74
package/index.js
CHANGED
|
@@ -27,8 +27,6 @@ async function main() {
|
|
|
27
27
|
process.exit(1);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
let conventionalCommit = false;
|
|
31
|
-
|
|
32
30
|
const diff = execSync("git diff --cached", { encoding: "utf8" });
|
|
33
31
|
|
|
34
32
|
if (!diff) {
|
|
@@ -47,11 +45,7 @@ async function main() {
|
|
|
47
45
|
process.exit(1);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
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. ${
|
|
51
|
-
conventionalCommit
|
|
52
|
-
? "Preface the commit with 'feat:' if it is a feature or 'fix:' if it is a bug."
|
|
53
|
-
: "Do not preface the commit with anything."
|
|
54
|
-
} 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}`;
|
|
55
49
|
|
|
56
50
|
console.log(
|
|
57
51
|
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...\n")
|
|
@@ -59,9 +53,8 @@ async function main() {
|
|
|
59
53
|
const aiCommitMessage = await generateCommitMessage(prompt);
|
|
60
54
|
|
|
61
55
|
console.log(
|
|
62
|
-
chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage
|
|
56
|
+
chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage + "\n"
|
|
63
57
|
);
|
|
64
|
-
console.log("\n");
|
|
65
58
|
|
|
66
59
|
const confirmationMessage = await inquirer.prompt([
|
|
67
60
|
{
|
package/package.json
CHANGED
package/aicommit.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env zx
|
|
2
|
-
|
|
3
|
-
void (async function () {
|
|
4
|
-
$.verbose = false;
|
|
5
|
-
|
|
6
|
-
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
|
|
7
|
-
|
|
8
|
-
let pwd = await $`cd ~ && pwd;`;
|
|
9
|
-
|
|
10
|
-
let { OPENAI_API_KEY } = await fs.readJson(
|
|
11
|
-
`${pwd.stdout.trim()}/ai-commit/.env.json`
|
|
12
|
-
);
|
|
13
|
-
let diff = await $`git diff --cached`;
|
|
14
|
-
|
|
15
|
-
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
|
16
|
-
if (diff.stdout.length > 8000) {
|
|
17
|
-
console.log("The diff is too large to write a commit message.");
|
|
18
|
-
await $`exit 1`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (diff.stdout.length === 0) {
|
|
22
|
-
console.log(
|
|
23
|
-
"No staged changes found. Make sure there are changes and run `git add .`"
|
|
24
|
-
);
|
|
25
|
-
await $`exit 1`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
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}`;
|
|
29
|
-
|
|
30
|
-
const payload = {
|
|
31
|
-
model: "text-davinci-003",
|
|
32
|
-
prompt,
|
|
33
|
-
temperature: 0.7,
|
|
34
|
-
top_p: 1,
|
|
35
|
-
frequency_penalty: 0,
|
|
36
|
-
presence_penalty: 0,
|
|
37
|
-
max_tokens: 200,
|
|
38
|
-
stream: false,
|
|
39
|
-
n: 1,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
console.log(
|
|
43
|
-
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...")
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const response = await fetch("https://api.openai.com/v1/completions", {
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": "application/json",
|
|
49
|
-
Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`,
|
|
50
|
-
},
|
|
51
|
-
method: "POST",
|
|
52
|
-
body: JSON.stringify(payload),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const json = await response.json();
|
|
56
|
-
const aiCommit = json.choices[0].text;
|
|
57
|
-
let cleanedUpAiCommit = aiCommit.replace(/(\r\n|\n|\r)/gm, "");
|
|
58
|
-
|
|
59
|
-
echo(cleanedUpAiCommit);
|
|
60
|
-
|
|
61
|
-
let confirmationMessage = await question(
|
|
62
|
-
"\nWould you like to use this commit message? " + chalk.yellow("(Y/n) "),
|
|
63
|
-
{
|
|
64
|
-
choices: ["Y", "n"],
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
$.verbose = true;
|
|
69
|
-
echo("\n");
|
|
70
|
-
|
|
71
|
-
if (confirmationMessage !== "n") {
|
|
72
|
-
await $`git commit -m ${cleanedUpAiCommit}`;
|
|
73
|
-
}
|
|
74
|
-
})();
|