git-aicommit 2.0.1 → 3.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 CHANGED
@@ -1,2 +1 @@
1
1
  OPENAI_API_KEY=
2
- GIT_AI_COMMIT_CONFIG_NAME=.git-ai-commit-config.js
package/README.md CHANGED
@@ -12,40 +12,72 @@ Tired of writing commit messages? Let the computer do it for you!
12
12
  npm install -g git-aicommit
13
13
  ```
14
14
 
15
- ## Usage
15
+ ## Configuration
16
+
17
+ This cli tool uses [standard rc files](https://www.npmjs.com/package/rc#standards):
18
+
19
+ - local `.git-aicommitrc`
20
+ - `$HOME/.git-aicommitrc`
21
+ - `$HOME/.git-aicommit/config`
22
+ - `$HOME/.config/git-aicommit`
23
+ - `$HOME/.config/git-aicommit/config`
24
+ - `/etc/git-aicommitrc`
25
+ - `/etc/git-aicommit/config`
16
26
 
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 (you can get one at [https://beta.openai.com/account/api-keys]())
19
- - `GIT_AI_AUTOCOMMIT` - If this env is present and not empty,
20
- the commit will be made automatically.
21
- Otherwise, you will just see the suggested commit.
27
+ Or [default config](config.js) is used if no config file is found.
28
+
29
+ To override default config, create a config file and export an object with the following properties:
22
30
 
23
31
  ```bash
24
- OPENAI_API_KEY=YOUR_OPEN_API_KEY GIT_AI_AUTOCOMMIT=1 git-aicommit
32
+ touch $HOME/.git-aicommitrc
25
33
  ```
26
34
 
27
- Or make an alias:
35
+ ```js
36
+ // $HOME/.git-aicommitrc
37
+ module.exports = {
38
+ openAiKey: process.env.OPENAI_API_KEY,
39
+ addAllChangesBeforeCommit: true,
40
+ autocommit: true,
41
+ openCommitTextEditor: false,
42
+ promptBeforeDiff: 'Read the following git diff for a multiple files:',
43
+ promptAfterDiff: 'Generate 1 to 3 paragraphs to explain this diff to a human without mentioning changes themselves:',
44
+ excludeFromDiff: [
45
+ '*.lock'
46
+ ],
47
+ diffFilter: 'ACMRTUXB',
48
+ completionPromptParams: {
49
+ model: "text-davinci-002",
50
+ max_tokens: 500,
51
+ temperature: 0.2,
52
+ top_p: 1,
53
+ presence_penalty: 0,
54
+ frequency_penalty: 0,
55
+ best_of: 1,
56
+ n: 1,
57
+ stream: false,
58
+ stop: ["\n\n\n"],
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Command line arguments
28
64
 
29
65
  ```bash
30
- alias gai='OPENAI_API_KEY=YOUR_OPEN_API_KEY GIT_AI_AUTOCOMMIT=1 git-aicommit'
66
+ git-aicommit --openAiKey="sk-..." --completionPromptParams.temperature=0.3 --no-autocommit
31
67
  ```
32
-
33
- Or export envs first:
68
+ ## Usage
34
69
 
35
70
  ```bash
36
- export OPENAI_API_KEY=YOUR_OPEN_API_KEY
37
- export GIT_AI_AUTOCOMMIT=1
71
+ export OPENAI_API_KEY=sk-YOUR_API_KEY
38
72
  git-aicommit
39
73
  ```
40
74
 
41
- Or even better: make an alias and export envs:
75
+ Or make an alias:
42
76
 
43
77
  ```bash
44
78
  alias gai='git-aicommit'
45
- export OPENAI_API_KEY=YOUR_OPEN_API_KEY
46
- export GIT_AI_AUTOCOMMIT=1
47
79
 
48
- # And run it:
80
+ ## And run it:
49
81
  gai
50
82
  ```
51
83
 
package/autocommit.js CHANGED
@@ -3,12 +3,9 @@
3
3
  require('dotenv').config();
4
4
  const {Configuration, OpenAIApi} = require("openai");
5
5
  const {execSync, spawn} = require("child_process");
6
+ const rc = require('rc');
6
7
 
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;
8
+ const defaultConfig = require('./config.js');
12
9
 
13
10
  // if (!fs.existsSync(configPath)) {
14
11
  // TODO: param to create default config file
@@ -18,7 +15,7 @@ const configPath = os.homedir() + '/' + configFilename;
18
15
  // console.log(`Created default config file at ${configPath}`);
19
16
  // }
20
17
 
21
- const config = !fs.existsSync(configPath) ? require('./config.js') : require(configPath);
18
+ const config = rc('git-aicommit', defaultConfig);
22
19
 
23
20
  try {
24
21
  execSync(
package/config.js CHANGED
@@ -4,7 +4,7 @@ module.exports = {
4
4
  autocommit: true,
5
5
  openCommitTextEditor: false,
6
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:',
7
+ promptAfterDiff: 'Generate 1 to 3 paragraphs to explain this diff to a human without mentioning changes themselves:',
8
8
  excludeFromDiff: [
9
9
  '*.lock'
10
10
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-aicommit",
3
- "version": "2.0.1",
3
+ "version": "3.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",
@@ -8,7 +8,8 @@
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
10
  "dotenv": "^16.0.2",
11
- "openai": "^3.0.0"
11
+ "openai": "^3.0.0",
12
+ "rc": "1.2.8"
12
13
  },
13
14
  "preferGlobal": true,
14
15
  "bin": {