git-aicommit 7.0.1 → 7.2.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.
@@ -0,0 +1,73 @@
1
+ name: Auto Release on Version Change
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 1
18
+
19
+ - name: Get Version from package.json
20
+ id: get_version
21
+ run: echo "version=$(jq -r '.version' package.json)" >> $GITHUB_OUTPUT
22
+ shell: bash
23
+
24
+ - name: Check if tag exists remotely
25
+ id: check_tag
26
+ run: |
27
+ PACKAGE_VERSION="${{ steps.get_version.outputs.version }}"
28
+ TAG_NAME="v${PACKAGE_VERSION}" # Standard v-prefix for tags
29
+ echo "Checking for remote tag: ${TAG_NAME}"
30
+
31
+ TAG_EXISTS_COUNT=$(git ls-remote --tags origin "refs/tags/${TAG_NAME}" | wc -l)
32
+
33
+ if [ "$TAG_EXISTS_COUNT" -ne 0 ]; then
34
+ echo "Tag ${TAG_NAME} already exists remotely."
35
+ echo "exists=true" >> $GITHUB_OUTPUT
36
+ else
37
+ echo "Tag ${TAG_NAME} does not exist remotely. Proceeding."
38
+ echo "exists=false" >> $GITHUB_OUTPUT
39
+ fi
40
+ shell: bash
41
+
42
+ - name: Fail workflow if tag already exists
43
+ if: steps.check_tag.outputs.exists == 'true'
44
+ run: |
45
+ PACKAGE_VERSION="${{ steps.get_version.outputs.version }}"
46
+ TAG_NAME="v${PACKAGE_VERSION}"
47
+ echo "::error title=Tag Exists::Tag ${TAG_NAME} already exists. Halting release process."
48
+ exit 1 # This will fail the job and stop further execution
49
+ shell: bash
50
+
51
+ - name: Create Release (and Git Tag)
52
+ uses: actions/create-release@v1
53
+ with:
54
+ tag_name: v${{ steps.get_version.outputs.version }}
55
+ release_name: Release v${{ steps.get_version.outputs.version }}
56
+ draft: false
57
+ prerelease: false
58
+ env:
59
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60
+
61
+ - name: Setup Node.js
62
+ uses: actions/setup-node@v3 # Can update to v4 if available and desired
63
+ with:
64
+ node-version: 18
65
+ registry-url: https://registry.npmjs.org/
66
+
67
+ - name: Install dependencies
68
+ run: npm ci
69
+
70
+ - name: Publish to npm
71
+ run: npm publish
72
+ env:
73
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/README.md CHANGED
@@ -36,30 +36,33 @@ touch $HOME/.git-aicommitrc
36
36
  // $HOME/.git-aicommitrc
37
37
  export default {
38
38
  openAiKey: process.env.OPENAI_API_KEY,
39
- addAllChangesBeforeCommit: true,
39
+ azureOpenAiKey: process.env.AZURE_OPENAI_API_KEY,
40
+ azureOpenAiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
41
+ azureOpenAiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
42
+ azureOpenAiVersion: process.env.AZURE_OPENAI_API_VERSION,
40
43
  autocommit: true,
41
44
  openCommitTextEditor: false,
42
45
  language: 'english',
43
46
  systemMessagePromptTemplate: '' +
44
- 'You are expert AI, your job is to write clear and concise Git commit messages.' +
47
+ 'You are expert software developer, your job is to write clear and concise Git commit messages. ' +
45
48
  'Your responsibility is to ensure that these messages accurately describe the changes made in each commit,' +
46
49
  'follow established guidelines. Provide a clear history of changes to the codebase.' +
47
50
  'Write 1-2 sentences. Output only the commit message without comments or other text.',
48
51
  humanPromptTemplate: '' +
49
52
  'Read the following git diff for a multiple files and ' +
50
53
  'write 1-2 sentences commit message in {language}' +
51
- 'without mentioning lines or files:\n' +
54
+ 'without mentioning lines or files.' +
55
+ 'If the reason behind the changed can be deducted from the changed, provide this reason:\n' +
52
56
  '{diff}',
53
57
  excludeFromDiff: [
54
- '*.lock', '*.lockb'
58
+ '*.lock', '*.lockb', '*-lock.json', '*-lock.yaml'
55
59
  ],
56
60
  diffFilter: 'ACMRTUXB',
57
- completionPromptParams: {
58
- model: "gpt-4o-mini",
59
- temperature: 0.0,
60
- maxTokens: 1000,
61
- }
61
+ modelName: "gpt-4.1-mini",
62
+ temperature: 0.0,
63
+ maxTokens: 2000,
62
64
  }
65
+
63
66
  ```
64
67
 
65
68
  ### Command line arguments
@@ -77,7 +80,7 @@ git-aicommit
77
80
  Or make an alias:
78
81
 
79
82
  ```bash
80
- alias gai='git-aicommit'
83
+ alias gai="git add --all && git-aicommit && git push"
81
84
 
82
85
  ## And run it:
83
86
  gai
package/autocommit.js CHANGED
@@ -58,12 +58,13 @@ if (!diff) {
58
58
  const openai = new OpenAI({
59
59
  apiKey: config.openAiKey,
60
60
  baseURL: config.azureOpenAiKey ? `https://${config.azureOpenAiInstanceName}.openai.azure.com/openai/deployments/${config.azureOpenAiDeploymentName}` : undefined,
61
- defaultHeaders: config.azureOpenAiKey ? { 'api-key': config.azureOpenAiKey } : undefined
61
+ defaultHeaders: config.azureOpenAiKey ? { 'api-key': config.azureOpenAiKey } : undefined,
62
+ defaultQuery: config.azureOpenAiKey ? { 'api-version': config.azureOpenAiVersion } : undefined, // defaultQuery for api-version as per OpenAI SDK v4+ for Azure
62
63
  });
63
64
 
64
65
  async function getChatCompletion(messages) {
65
66
  const response = await openai.chat.completions.create({
66
- model: config.modelName || 'gpt-4o-mini',
67
+ model: config.modelName || 'gpt-4.1-mini',
67
68
  messages: messages,
68
69
  temperature: config.temperature,
69
70
  max_tokens: config.maxTokens,
@@ -75,24 +76,21 @@ async function getChatCompletion(messages) {
75
76
  const systemMessage = { role: "system", content: config.systemMessagePromptTemplate };
76
77
  const userMessage = { role: "user", content: config.humanPromptTemplate.replace("{diff}", diff).replace("{language}", config.language) };
77
78
 
78
- const chatMessages = [systemMessage, userMessage];
79
-
80
79
  const tokenCount = await calculateMaxTokens({
81
80
  prompt: diff,
82
- modelName: config.modelName || 'gpt-4o-mini'
81
+ modelName: config.modelName || 'gpt-4.1-mini'
83
82
  });
84
83
 
85
- const contextSize = getModelContextSize(config.modelName || 'gpt-4o-mini');
84
+ const contextSize = getModelContextSize(config.modelName || 'gpt-4.1-mini');
86
85
 
87
86
  if (tokenCount > contextSize) {
88
- console.log('Diff is too long. Please lower the amount of changes in the commit or switch to a model with bigger context size');
89
-
87
+ console.log('Diff is too long for the current model context. Please lower the amount of changes in the commit or switch to a model with a larger context window.');
90
88
  process.exit(1);
91
89
  }
92
90
 
93
91
  const messages = [
94
- { role: "system", content: config.systemMessagePromptTemplate },
95
- { role: "user", content: config.humanPromptTemplate.replace("{diff}", diff).replace("{language}", config.language) }
92
+ systemMessage,
93
+ userMessage
96
94
  ];
97
95
 
98
96
  const commitMessage = await getChatCompletion(messages);
@@ -101,10 +99,19 @@ if (!config.autocommit) {
101
99
  console.log(`Autocommit is disabled. Here is the message:\n ${commitMessage}`);
102
100
  } else {
103
101
  console.log(`Committing with following message:\n ${commitMessage}`);
104
- execSync(
105
- `git commit -m "${commitMessage.replace(/"/g, '')}"`,
106
- {encoding: 'utf8'}
107
- );
102
+ try {
103
+ execSync(
104
+ 'git commit -F -',
105
+ {
106
+ input: commitMessage,
107
+ encoding: 'utf8',
108
+ stdio: 'inherit'
109
+ }
110
+ );
111
+ } catch (error) {
112
+ console.error("Failed to commit.", error);
113
+ process.exit(1);
114
+ }
108
115
  }
109
116
 
110
117
  if (config.openCommitTextEditor) {
package/config.js CHANGED
@@ -22,7 +22,7 @@ export default {
22
22
  '*.lock', '*.lockb', '*-lock.json', '*-lock.yaml'
23
23
  ],
24
24
  diffFilter: 'ACMRTUXB',
25
- modelName: "gpt-4o-mini",
25
+ modelName: "gpt-4.1-mini",
26
26
  temperature: 0.0,
27
27
  maxTokens: 2000,
28
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-aicommit",
3
- "version": "7.0.1",
3
+ "version": "7.2.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,9 +8,9 @@
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "dependencies": {
11
- "openai": "^4.52.7",
11
+ "openai": "^4.100.0",
12
12
  "rc": "^1.2.8",
13
- "tiktoken": "^1.0.15"
13
+ "tiktoken": "^1.0.21"
14
14
  },
15
15
  "preferGlobal": true,
16
16
  "bin": {
@@ -1,19 +0,0 @@
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: 18
15
- registry-url: https://registry.npmjs.org/
16
- - run: npm ci
17
- - run: npm publish
18
- env:
19
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}