git-commit-msg-ai 1.0.0__py3-none-any.whl
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.
commit_msg.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
from typing import cast
|
|
5
|
+
import anthropic
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
diff = subprocess.check_output(['git', 'diff', '--cached']).decode()
|
|
10
|
+
|
|
11
|
+
client = anthropic.Anthropic()
|
|
12
|
+
response = client.messages.create(
|
|
13
|
+
model='claude-haiku-4-5-20251001',
|
|
14
|
+
max_tokens=1024,
|
|
15
|
+
system=(
|
|
16
|
+
'You are a Git commit message generator. Output only the commit message, nothing else. '
|
|
17
|
+
'Follow the Conventional Commits specification:\n'
|
|
18
|
+
'- First line: <type>(<optional scope>)<!>: <short subject> (50 chars max); '
|
|
19
|
+
'append ! before the colon if the commit introduces a breaking change\n'
|
|
20
|
+
'- Blank line\n'
|
|
21
|
+
'- Bullet-point body explaining WHY the changes were made, not what\n'
|
|
22
|
+
'- If there is a breaking change, add a blank line after the body followed by '
|
|
23
|
+
'"BREAKING CHANGE: <description of what breaks and why>\n'
|
|
24
|
+
'Types: feat, fix, docs, style, refactor, test, chore'
|
|
25
|
+
),
|
|
26
|
+
messages=[{'role': 'user', 'content': diff}],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
msg = cast(anthropic.types.TextBlock, response.content[0]).text.strip()
|
|
30
|
+
print(msg)
|
|
31
|
+
|
|
32
|
+
choice = input('\n[a]ccept / [e]dit / [r]eject: ').strip().lower()
|
|
33
|
+
|
|
34
|
+
if choice == 'a':
|
|
35
|
+
subprocess.run(['git', 'commit', '-m', msg])
|
|
36
|
+
elif choice == 'e':
|
|
37
|
+
with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as f:
|
|
38
|
+
f.write(msg)
|
|
39
|
+
tmp = f.name
|
|
40
|
+
subprocess.run([os.environ.get('EDITOR', 'notepad'), tmp])
|
|
41
|
+
with open(tmp) as f:
|
|
42
|
+
msg = f.read().strip()
|
|
43
|
+
os.unlink(tmp)
|
|
44
|
+
subprocess.run(['git', 'commit', '-m', msg])
|
|
45
|
+
elif choice == 'r':
|
|
46
|
+
print('User rejected the generated commit message. No commit made.')
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
main()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: git-commit-msg-ai
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: AI-powered git commit message generator following Conventional Commits
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: anthropic
|
|
9
|
+
|
|
10
|
+
# git-commit-msg-ai
|
|
11
|
+
|
|
12
|
+
AI-powered git commit message generator that follows the [Conventional Commits](https://www.conventionalcommits.org/) specification.
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- Python 3.9+
|
|
17
|
+
- An Anthropic API key set as an environment variable:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
export ANTHROPIC_API_KEY=sk-ant-... # macOS/Linux
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', 'sk-ant-...', 'User') # Windows
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pip install git-commit-msg-ai
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
Stage your changes, then run the tool from inside any git repository:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
git add <files>
|
|
39
|
+
git-commit-msg-ai
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The tool will:
|
|
43
|
+
1. Read your staged diff
|
|
44
|
+
2. Generate a commit message using Claude AI
|
|
45
|
+
3. Print the message and prompt you to choose:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
[a]ccept / [e]dit / [r]eject:
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- **a** — commits immediately with the generated message
|
|
52
|
+
- **e** — opens the message in your `$EDITOR`, lets you modify it, then commits
|
|
53
|
+
- **r** — exits without committing
|
|
54
|
+
|
|
55
|
+
## Commit message format
|
|
56
|
+
|
|
57
|
+
Generated messages follow the Conventional Commits specification:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
<type>(<optional scope>): <short subject>
|
|
61
|
+
|
|
62
|
+
- Bullet explaining why this change was made
|
|
63
|
+
- Another reason if applicable
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For breaking changes, the subject line gets a `!` and a footer is added:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
feat(api)!: remove deprecated endpoint
|
|
70
|
+
|
|
71
|
+
- Endpoint was unused and blocking the new auth rollout
|
|
72
|
+
|
|
73
|
+
BREAKING CHANGE: /v1/legacy is no longer available
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Supported types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
commit_msg.py,sha256=8jfalkufA0BxVHJzEegY7nCUA9b0b7HlSp5dXCm0XGw,1832
|
|
2
|
+
git_commit_msg_ai-1.0.0.dist-info/METADATA,sha256=ckC9Sqq6jeUrCyl5BW8Z7ksJOyIbOVyPeQdtm8DfavA,1820
|
|
3
|
+
git_commit_msg_ai-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
4
|
+
git_commit_msg_ai-1.0.0.dist-info/entry_points.txt,sha256=6c2u6AJ08tD5_ZHIm3kLOXg9NdcRgUcdqmf8sN9EGIE,54
|
|
5
|
+
git_commit_msg_ai-1.0.0.dist-info/top_level.txt,sha256=ZybdMozy1k619MPQuC0axGNbHbu97uYGjoV3B-o7sb4,11
|
|
6
|
+
git_commit_msg_ai-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
commit_msg
|