git-aicommit 1.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/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ OPENAI_API_KEY=
2
+ GIT_AUTOCOMMIT=
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptLibraryMappings">
4
+ <includedPredefinedLibrary name="Node.js Core" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/autocommit.iml" filepath="$PROJECT_DIR$/.idea/autocommit.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
package/autocommit.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('dotenv').config();
4
+ const {Configuration, OpenAIApi} = require("openai");
5
+ const {execSync} = require("child_process");
6
+
7
+ try {
8
+ execSync(
9
+ 'git rev-parse --is-inside-work-tree 2>/dev/null',
10
+ {encoding: 'utf8'}
11
+ );
12
+ } catch (e) {
13
+ console.error("This is not a git repository");
14
+ process.exit(1);
15
+ }
16
+
17
+ if (!process.env.OPENAI_API_KEY) {
18
+ console.error("Please set OPENAI_API_KEY");
19
+ process.exit(1);
20
+ }
21
+
22
+ const diff = execSync(
23
+ `git diff -- . ':(exclude)*.lock' 2>/dev/null`,
24
+ {encoding: 'utf8'}
25
+ );
26
+
27
+ // if diff is empty exit
28
+ if (!diff) {
29
+ console.error("Diff seems empty. Please commit manually.");
30
+ process.exit(1);
31
+ }
32
+
33
+
34
+ const configuration = new Configuration({
35
+ apiKey: process.env.OPENAI_API_KEY,
36
+ });
37
+
38
+ const openai = new OpenAIApi(configuration);
39
+
40
+ // create a prompt
41
+ const prompt = `Read the following git diff for a multiple files:
42
+
43
+ ${diff}
44
+
45
+ Generate a commit message to explain diff in each file:
46
+
47
+ `;
48
+
49
+ openai
50
+ .createCompletion({
51
+ prompt,
52
+ model: "text-davinci-002",
53
+ max_tokens: 500,
54
+ temperature: 0.2,
55
+ top_p: 1,
56
+ presence_penalty: 0,
57
+ frequency_penalty: 0,
58
+ best_of: 1,
59
+ n: 1,
60
+ stream: false,
61
+ stop: ["\n\n\n"],
62
+ })
63
+ .then((data) => {
64
+ const commitMessage = data.data.choices[0].text;
65
+ const command = `git add --all && git commit -m "${commitMessage}"`;
66
+
67
+ if (!process.env.GIT_AUTOCOMMIT) {
68
+ console.log(`Please set GIT_AUTOCOMMIT to commit with following command:\n ${command}`);
69
+ } else {
70
+ console.log(`Committing with following command:\n ${command}`);
71
+ execSync(command, {encoding: 'utf8'});
72
+ }
73
+ });
74
+
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "git-aicommit",
3
+ "version": "1.0.0",
4
+ "description": "Generates auto commit messages with OpenAI GPT3 model",
5
+ "main": "autocommit.js",
6
+ "repository": "https://github.com/shanginn/autocommit",
7
+ "author": "shanginn@gmail.com",
8
+ "license": "MIT",
9
+ "dependencies": {
10
+ "dotenv": "^16.0.2",
11
+ "openai": "^3.0.0"
12
+ }
13
+ }