git-aicommit 3.0.0 → 4.0.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.
- package/.github/workflows/npm-publish.yml +19 -0
- package/autocommit.js +54 -57
- package/config.js +16 -14
- package/package.json +3 -1
- package/yarn-error.log +0 -36
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Node.js Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish-npm:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- uses: actions/setup-node@v3
|
|
13
|
+
with:
|
|
14
|
+
node-version: 16
|
|
15
|
+
registry-url: https://registry.npmjs.org/
|
|
16
|
+
- run: npm ci
|
|
17
|
+
- run: npm publish
|
|
18
|
+
env:
|
|
19
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/autocommit.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { execSync, spawn } from "child_process";
|
|
4
|
+
import rc from 'rc';
|
|
5
|
+
import { ChatOpenAI } from "langchain/chat_models";
|
|
6
|
+
import {ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate} from "langchain/prompts";
|
|
7
|
+
import defaultConfig from './config.js';
|
|
8
|
+
import dotenv from 'dotenv';
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
dotenv.config();
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const config = rc('git-aicommit', defaultConfig);
|
|
12
|
+
const config = rc(
|
|
13
|
+
'git-aicommit',
|
|
14
|
+
{
|
|
15
|
+
...defaultConfig,
|
|
16
|
+
openAiKey: process.env.OPENAI_API_KEY,
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
21
|
execSync(
|
|
22
|
-
'git rev-parse --is-inside-work-tree
|
|
23
|
-
{encoding: 'utf8'}
|
|
22
|
+
'git rev-parse --is-inside-work-tree',
|
|
23
|
+
{encoding: 'utf8', stdio: 'ignore'}
|
|
24
24
|
);
|
|
25
25
|
} catch (e) {
|
|
26
26
|
console.error("This is not a git repository");
|
|
@@ -34,10 +34,11 @@ if (!config.openAiKey) {
|
|
|
34
34
|
|
|
35
35
|
const excludeFromDiff = config.excludeFromDiff || [];
|
|
36
36
|
const diffFilter = config.diffFilter || 'ACMRTUXB';
|
|
37
|
-
const diffCommand = `git diff \
|
|
37
|
+
const diffCommand = `git diff --staged \
|
|
38
38
|
--diff-filter=${diffFilter} \
|
|
39
|
-
${excludeFromDiff.map(
|
|
40
|
-
|
|
39
|
+
-- "${excludeFromDiff.map(
|
|
40
|
+
(pattern) => `:(exclude)${pattern}`
|
|
41
|
+
).join(' ')}"
|
|
41
42
|
`;
|
|
42
43
|
|
|
43
44
|
const diff = execSync(diffCommand, {encoding: 'utf8'});
|
|
@@ -47,47 +48,43 @@ if (!diff) {
|
|
|
47
48
|
process.exit(1);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const openai = new
|
|
51
|
+
const openai = new ChatOpenAI({
|
|
52
|
+
modelName: config.modelName,
|
|
51
53
|
apiKey: config.openAiKey,
|
|
52
|
-
|
|
54
|
+
temperature: config.temperature,
|
|
55
|
+
maxTokens: config.maxTokens,
|
|
56
|
+
});
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
const
|
|
58
|
+
const systemMessagePromptTemplate = SystemMessagePromptTemplate.fromTemplate(config.systemMessagePromptTemplate)
|
|
59
|
+
const humanPromptTemplate = HumanMessagePromptTemplate.fromTemplate(config.humanPromptTemplate)
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
const chatPrompt = ChatPromptTemplate.fromPromptMessages([
|
|
62
|
+
systemMessagePromptTemplate,
|
|
63
|
+
humanPromptTemplate,
|
|
64
|
+
])
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
const prompt = await chatPrompt.formatMessages({
|
|
67
|
+
diff: diff,
|
|
68
|
+
language: config.language,
|
|
69
|
+
})
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
const res = await openai.call(prompt)
|
|
72
|
+
|
|
73
|
+
const commitMessage = res.text.trim();
|
|
62
74
|
|
|
63
|
-
openai
|
|
64
|
-
.createCompletion({
|
|
65
|
-
prompt,
|
|
66
|
-
...config.completionPromptParams
|
|
67
|
-
})
|
|
68
|
-
.then((data) => {
|
|
69
|
-
const commitMessage = data.data.choices[0].text;
|
|
70
|
-
|
|
71
|
-
if (!config.addAllChangesBeforeCommit) {
|
|
72
|
-
console.log('addAllChangesBeforeCommit is false. Skipping git add --all');
|
|
73
|
-
} else {
|
|
74
|
-
execSync('git add --all', {encoding: 'utf8'});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!config.autocommit) {
|
|
78
|
-
console.log(`Autocommit is disabled. Here is the message:\n ${commitMessage}`);
|
|
79
|
-
} else {
|
|
80
|
-
console.log(`Committing with following message:\n ${commitMessage}`);
|
|
81
|
-
execSync(
|
|
82
|
-
`git commit -m "${commitMessage.replace(/"/g, '')}"`,
|
|
83
|
-
{encoding: 'utf8'}
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
if (config.openCommitTextEditor) {
|
|
87
|
-
spawn('git', ['commit', '--amend'], {
|
|
88
|
-
stdio: 'inherit'
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
75
|
|
|
76
|
+
if (!config.autocommit) {
|
|
77
|
+
console.log(`Autocommit is disabled. Here is the message:\n ${commitMessage}`);
|
|
78
|
+
} else {
|
|
79
|
+
console.log(`Committing with following message:\n ${commitMessage}`);
|
|
80
|
+
execSync(
|
|
81
|
+
`git commit -m "${commitMessage.replace(/"/g, '')}"`,
|
|
82
|
+
{encoding: 'utf8'}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (config.openCommitTextEditor) {
|
|
87
|
+
spawn('git', ['commit', '--amend'], {
|
|
88
|
+
stdio: 'inherit'
|
|
89
|
+
});
|
|
90
|
+
}
|
package/config.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
export default {
|
|
2
2
|
openAiKey: process.env.OPENAI_API_KEY,
|
|
3
3
|
addAllChangesBeforeCommit: true,
|
|
4
4
|
autocommit: true,
|
|
5
5
|
openCommitTextEditor: false,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
language: 'english',
|
|
7
|
+
systemMessagePromptTemplate: '' +
|
|
8
|
+
'You are expert AI, your job is to write clear and concise Git commit messages.' +
|
|
9
|
+
'Your responsibility is to ensure that these messages accurately describe the changes made in each commit,' +
|
|
10
|
+
'follow established guidelines. Provide a clear history of changes to the codebase.' +
|
|
11
|
+
'Write 1-2 sentences. Output only the commit message without comments or other text.',
|
|
12
|
+
humanPromptTemplate: '' +
|
|
13
|
+
'Read the following git diff for a multiple files and ' +
|
|
14
|
+
'write 1-2 sentences commit message in {language}' +
|
|
15
|
+
'without mentioning lines or files:\n' +
|
|
16
|
+
'{diff}',
|
|
8
17
|
excludeFromDiff: [
|
|
9
|
-
'*.lock'
|
|
18
|
+
'*.lock', '*.lockb'
|
|
10
19
|
],
|
|
11
20
|
diffFilter: 'ACMRTUXB',
|
|
12
21
|
completionPromptParams: {
|
|
13
|
-
model: "
|
|
14
|
-
|
|
15
|
-
|
|
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"],
|
|
22
|
+
model: "gpt-3.5-turbo",
|
|
23
|
+
temperature: 0.0,
|
|
24
|
+
maxTokens: 1000,
|
|
23
25
|
}
|
|
24
26
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-aicommit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Generates auto commit messages with OpenAI GPT3 model",
|
|
5
5
|
"main": "autocommit.js",
|
|
6
6
|
"repository": "https://github.com/shanginn/autocommit",
|
|
7
7
|
"author": "shanginn@gmail.com",
|
|
8
8
|
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"dependencies": {
|
|
10
11
|
"dotenv": "^16.0.2",
|
|
12
|
+
"langchain": "^0.0.47",
|
|
11
13
|
"openai": "^3.0.0",
|
|
12
14
|
"rc": "1.2.8"
|
|
13
15
|
},
|
package/yarn-error.log
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|