git-aicommit 1.3.0 → 2.0.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/.env.example +1 -1
- package/README.md +16 -5
- package/autocommit.js +52 -29
- package/config.js +24 -0
- package/package.json +1 -1
- package/yarn-error.log +36 -0
package/.env.example
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
OPENAI_API_KEY=
|
|
2
|
-
|
|
2
|
+
GIT_AI_COMMIT_CONFIG_NAME=.git-ai-commit-config.js
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Tired of writing commit messages? Let the computer do it for you!
|
|
|
4
4
|
|
|
5
5
|
[](https://asciinema.org/a/fpL5Dkd74xO8yRTM15O49zOF9)
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> It's shit, but better than "WIP"!
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -15,13 +15,11 @@ npm install -g git-aicommit
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
For now this cli tool uses env variables to pass params, because this is simple PoC.
|
|
18
|
-
- `OPENAI_API_KEY` - your OpenAI API key
|
|
18
|
+
- `OPENAI_API_KEY` - your OpenAI API key (you can get one at [https://beta.openai.com/account/api-keys]())
|
|
19
19
|
- `GIT_AI_AUTOCOMMIT` - If this env is present and not empty,
|
|
20
20
|
the commit will be made automatically.
|
|
21
21
|
Otherwise, you will just see the suggested commit.
|
|
22
22
|
|
|
23
|
-
```bash
|
|
24
|
-
|
|
25
23
|
```bash
|
|
26
24
|
OPENAI_API_KEY=YOUR_OPEN_API_KEY GIT_AI_AUTOCOMMIT=1 git-aicommit
|
|
27
25
|
```
|
|
@@ -40,4 +38,17 @@ export GIT_AI_AUTOCOMMIT=1
|
|
|
40
38
|
git-aicommit
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
Or make an alias and export envs:
|
|
41
|
+
Or even better: make an alias and export envs:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
alias gai='git-aicommit'
|
|
45
|
+
export OPENAI_API_KEY=YOUR_OPEN_API_KEY
|
|
46
|
+
export GIT_AI_AUTOCOMMIT=1
|
|
47
|
+
|
|
48
|
+
# And run it:
|
|
49
|
+
gai
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It that simple!
|
|
53
|
+
|
|
54
|
+
|
package/autocommit.js
CHANGED
|
@@ -2,7 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
require('dotenv').config();
|
|
4
4
|
const {Configuration, OpenAIApi} = require("openai");
|
|
5
|
-
const {execSync} = require("child_process");
|
|
5
|
+
const {execSync, spawn} = require("child_process");
|
|
6
|
+
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
|
|
10
|
+
const configFilename = process.env.GIT_AI_COMMIT_CONFIG_NAME || '.git-ai-commit-config.js';
|
|
11
|
+
const configPath = os.homedir() + '/' + configFilename;
|
|
12
|
+
|
|
13
|
+
// if (!fs.existsSync(configPath)) {
|
|
14
|
+
// TODO: param to create default config file
|
|
15
|
+
// const { defaultConfig } = require('./config.js');
|
|
16
|
+
//
|
|
17
|
+
// fs.writeFileSync(configPath, `module.exports = ${JSON.stringify(defaultConfig, null, 4)}`);
|
|
18
|
+
// console.log(`Created default config file at ${configPath}`);
|
|
19
|
+
// }
|
|
20
|
+
|
|
21
|
+
const config = !fs.existsSync(configPath) ? require('./config.js') : require(configPath);
|
|
6
22
|
|
|
7
23
|
try {
|
|
8
24
|
execSync(
|
|
@@ -14,60 +30,67 @@ try {
|
|
|
14
30
|
process.exit(1);
|
|
15
31
|
}
|
|
16
32
|
|
|
17
|
-
if (!
|
|
33
|
+
if (!config.openAiKey) {
|
|
18
34
|
console.error("Please set OPENAI_API_KEY");
|
|
19
35
|
process.exit(1);
|
|
20
36
|
}
|
|
21
37
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
const excludeFromDiff = config.excludeFromDiff || [];
|
|
39
|
+
const diffFilter = config.diffFilter || 'ACMRTUXB';
|
|
40
|
+
const diffCommand = `git diff \
|
|
41
|
+
--diff-filter=${diffFilter} \
|
|
42
|
+
${excludeFromDiff.map((pattern) => `-- ':(exclude)${pattern}'`).join(' ')} \
|
|
43
|
+
2>/dev/null
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const diff = execSync(diffCommand, {encoding: 'utf8'});
|
|
26
47
|
|
|
27
48
|
if (!diff) {
|
|
28
49
|
console.error("Diff seems empty. Please commit manually.");
|
|
29
50
|
process.exit(1);
|
|
30
51
|
}
|
|
31
52
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const openai = new OpenAIApi(configuration);
|
|
53
|
+
const openai = new OpenAIApi(new Configuration({
|
|
54
|
+
apiKey: config.openAiKey,
|
|
55
|
+
}));
|
|
38
56
|
|
|
39
57
|
// create a prompt
|
|
40
|
-
const prompt =
|
|
58
|
+
const prompt = `${config.promptBeforeDiff}
|
|
41
59
|
|
|
42
60
|
${diff}
|
|
43
61
|
|
|
44
|
-
|
|
62
|
+
${config.promptAfterDiff}
|
|
45
63
|
|
|
46
64
|
`;
|
|
47
65
|
|
|
48
66
|
openai
|
|
49
67
|
.createCompletion({
|
|
50
68
|
prompt,
|
|
51
|
-
|
|
52
|
-
max_tokens: 500,
|
|
53
|
-
temperature: 0.2,
|
|
54
|
-
top_p: 1,
|
|
55
|
-
presence_penalty: 0,
|
|
56
|
-
frequency_penalty: 0,
|
|
57
|
-
best_of: 1,
|
|
58
|
-
n: 1,
|
|
59
|
-
stream: false,
|
|
60
|
-
stop: ["\n\n\n"],
|
|
69
|
+
...config.completionPromptParams
|
|
61
70
|
})
|
|
62
71
|
.then((data) => {
|
|
63
72
|
const commitMessage = data.data.choices[0].text;
|
|
64
|
-
const command = `git add --all && git commit -m "${commitMessage.replace(/"/g, '\\"');}"`;
|
|
65
73
|
|
|
66
|
-
if (!
|
|
67
|
-
|
|
74
|
+
if (!config.addAllChangesBeforeCommit) {
|
|
75
|
+
console.log('addAllChangesBeforeCommit is false. Skipping git add --all');
|
|
76
|
+
} else {
|
|
77
|
+
execSync('git add --all', {encoding: 'utf8'});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!config.autocommit) {
|
|
81
|
+
console.log(`Autocommit is disabled. Here is the message:\n ${commitMessage}`);
|
|
68
82
|
} else {
|
|
69
|
-
console.log(`Committing with following
|
|
70
|
-
execSync(
|
|
83
|
+
console.log(`Committing with following message:\n ${commitMessage}`);
|
|
84
|
+
execSync(
|
|
85
|
+
`git commit -m "${commitMessage.replace(/"/g, '')}"`,
|
|
86
|
+
{encoding: 'utf8'}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (config.openCommitTextEditor) {
|
|
90
|
+
spawn('git', ['commit', '--amend'], {
|
|
91
|
+
stdio: 'inherit'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
71
94
|
}
|
|
72
95
|
});
|
|
73
96
|
|
package/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
openAiKey: process.env.OPENAI_API_KEY,
|
|
3
|
+
addAllChangesBeforeCommit: true,
|
|
4
|
+
autocommit: true,
|
|
5
|
+
openCommitTextEditor: false,
|
|
6
|
+
promptBeforeDiff: 'Read the following git diff for a multiple files:',
|
|
7
|
+
promptAfterDiff: 'Generate 1 to 3 paragraphs to explain this diff to a human:',
|
|
8
|
+
excludeFromDiff: [
|
|
9
|
+
'*.lock'
|
|
10
|
+
],
|
|
11
|
+
diffFilter: 'ACMRTUXB',
|
|
12
|
+
completionPromptParams: {
|
|
13
|
+
model: "text-davinci-002",
|
|
14
|
+
max_tokens: 500,
|
|
15
|
+
temperature: 0.2,
|
|
16
|
+
top_p: 1,
|
|
17
|
+
presence_penalty: 0,
|
|
18
|
+
frequency_penalty: 0,
|
|
19
|
+
best_of: 1,
|
|
20
|
+
n: 1,
|
|
21
|
+
stream: false,
|
|
22
|
+
stop: ["\n\n\n"],
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
package/yarn-error.log
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Arguments:
|
|
2
|
+
/Users/shanginn/.nvm/versions/node/v16.16.0/bin/node /usr/local/Cellar/yarn/1.22.19/libexec/bin/yarn.js init
|
|
3
|
+
|
|
4
|
+
PATH:
|
|
5
|
+
/Users/shanginn/.nvm/versions/node/v16.16.0/bin:/Users/shanginn/.bun/bin:/Users/shanginn/bin:/usr/local/bin:/Users/shanginn/go/bin:/Users/shanginn/.composer/vendor/bin/:/Users/shanginn/.local/share/solana/install/active_release/bin:/Users/shanginn/.bun/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/shanginn/.cargo/bin
|
|
6
|
+
|
|
7
|
+
Yarn version:
|
|
8
|
+
1.22.19
|
|
9
|
+
|
|
10
|
+
Node version:
|
|
11
|
+
16.16.0
|
|
12
|
+
|
|
13
|
+
Platform:
|
|
14
|
+
darwin x64
|
|
15
|
+
|
|
16
|
+
Trace:
|
|
17
|
+
Error: canceled
|
|
18
|
+
at Interface.<anonymous> (/usr/local/Cellar/yarn/1.22.19/libexec/lib/cli.js:137150:13)
|
|
19
|
+
at Interface.emit (node:events:527:28)
|
|
20
|
+
at Interface._ttyWrite (node:readline:1081:16)
|
|
21
|
+
at ReadStream.onkeypress (node:readline:288:10)
|
|
22
|
+
at ReadStream.emit (node:events:527:28)
|
|
23
|
+
at emitKeys (node:internal/readline/utils:358:14)
|
|
24
|
+
at emitKeys.next (<anonymous>)
|
|
25
|
+
at ReadStream.onData (node:internal/readline/emitKeypressEvents:61:36)
|
|
26
|
+
at ReadStream.emit (node:events:527:28)
|
|
27
|
+
at addChunk (node:internal/streams/readable:315:12)
|
|
28
|
+
|
|
29
|
+
npm manifest:
|
|
30
|
+
No manifest
|
|
31
|
+
|
|
32
|
+
yarn manifest:
|
|
33
|
+
No manifest
|
|
34
|
+
|
|
35
|
+
Lockfile:
|
|
36
|
+
No lockfile
|