git-commit-msg-ai 1.1.0__py3-none-any.whl → 1.2.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.
- git_commit_msg_ai/ai_client.py +21 -17
- git_commit_msg_ai/cli.py +22 -21
- git_commit_msg_ai/editor.py +13 -8
- git_commit_msg_ai/git_ops.py +4 -1
- {git_commit_msg_ai-1.1.0.dist-info → git_commit_msg_ai-1.2.0.dist-info}/METADATA +4 -1
- git_commit_msg_ai-1.2.0.dist-info/RECORD +10 -0
- git_commit_msg_ai-1.1.0.dist-info/RECORD +0 -10
- {git_commit_msg_ai-1.1.0.dist-info → git_commit_msg_ai-1.2.0.dist-info}/WHEEL +0 -0
- {git_commit_msg_ai-1.1.0.dist-info → git_commit_msg_ai-1.2.0.dist-info}/entry_points.txt +0 -0
- {git_commit_msg_ai-1.1.0.dist-info → git_commit_msg_ai-1.2.0.dist-info}/top_level.txt +0 -0
git_commit_msg_ai/ai_client.py
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import textwrap
|
|
2
|
+
from typing import Final, cast
|
|
3
|
+
|
|
2
4
|
import anthropic
|
|
3
5
|
|
|
4
|
-
SYSTEM_PROMPT = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'- If there is a breaking change, add a blank line after the body followed by '
|
|
12
|
-
'"BREAKING CHANGE: <description of what breaks and why>\n'
|
|
13
|
-
'Types: feat, fix, docs, style, refactor, test, chore'
|
|
14
|
-
)
|
|
6
|
+
SYSTEM_PROMPT: Final[str] = textwrap.dedent("""\
|
|
7
|
+
You are a Git commit message generator. Output only the commit message, nothing else. Follow the Conventional Commits specification:
|
|
8
|
+
- First line: <type>(<optional scope>)<!>: <short subject> (50 chars max); append ! before the colon if the commit introduces a breaking change
|
|
9
|
+
- Blank line
|
|
10
|
+
- Bullet-point body explaining WHY the changes were made, not what
|
|
11
|
+
- If there is a breaking change, add a blank line after the body followed by "BREAKING CHANGE: <description of what breaks and why>
|
|
12
|
+
Types: feat, fix, docs, style, refactor, test, chore""")
|
|
15
13
|
|
|
16
|
-
MODEL = 'claude-haiku-4-5-20251001'
|
|
17
|
-
MAX_TOKENS = 1024
|
|
14
|
+
MODEL: Final[str] = 'claude-haiku-4-5-20251001'
|
|
15
|
+
MAX_TOKENS: Final[int] = 1024
|
|
18
16
|
|
|
19
17
|
|
|
20
18
|
def generate_commit_message(diff: str) -> str:
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
anthropic_client = anthropic.Anthropic()
|
|
20
|
+
|
|
21
|
+
anthropic_api_response = anthropic_client.messages.create(
|
|
23
22
|
model=MODEL,
|
|
24
23
|
max_tokens=MAX_TOKENS,
|
|
25
24
|
system=SYSTEM_PROMPT,
|
|
26
25
|
messages=[{'role': 'user', 'content': diff}],
|
|
27
26
|
)
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
anthropic_api_response_message = anthropic_api_response.content[0]
|
|
29
|
+
commit_message = cast(anthropic.types.TextBlock, anthropic_api_response_message).text.strip()
|
|
30
|
+
|
|
31
|
+
return commit_message
|
|
32
|
+
|
git_commit_msg_ai/cli.py
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
from git_commit_msg_ai import ai_client, editor, git_ops
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def main() -> None:
|
|
5
|
-
diff = git_ops.get_staged_diff()
|
|
6
|
-
|
|
7
|
-
print(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
from git_commit_msg_ai import ai_client, editor, git_ops
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def main() -> None:
|
|
5
|
+
diff = git_ops.get_staged_diff()
|
|
6
|
+
commit_message = ai_client.generate_commit_message(diff)
|
|
7
|
+
print(commit_message)
|
|
8
|
+
|
|
9
|
+
print()
|
|
10
|
+
user_selection = input('[a]ccept / [e]dit / [r]eject: ').strip().lower()
|
|
11
|
+
|
|
12
|
+
if user_selection == 'a':
|
|
13
|
+
git_ops.commit(commit_message)
|
|
14
|
+
elif user_selection == 'e':
|
|
15
|
+
updated_commit_message = editor.open_in_editor(commit_message)
|
|
16
|
+
git_ops.commit(updated_commit_message)
|
|
17
|
+
elif user_selection == 'r':
|
|
18
|
+
print('User rejected the generated commit message. No commit made.')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
main()
|
git_commit_msg_ai/editor.py
CHANGED
|
@@ -4,11 +4,16 @@ import tempfile
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def open_in_editor(initial_text: str) -> str:
|
|
7
|
-
with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as temp_file:
|
|
8
|
+
temp_file.write(initial_text)
|
|
9
|
+
temp_file_path = temp_file.name
|
|
10
|
+
|
|
11
|
+
editor_command = os.environ.get('EDITOR', 'notepad')
|
|
12
|
+
subprocess.run([editor_command, temp_file_path])
|
|
13
|
+
|
|
14
|
+
with open(temp_file_path) as temp_file:
|
|
15
|
+
edited_text = temp_file.read().strip()
|
|
16
|
+
|
|
17
|
+
os.unlink(temp_file_path)
|
|
18
|
+
|
|
19
|
+
return edited_text
|
git_commit_msg_ai/git_ops.py
CHANGED
|
@@ -2,8 +2,11 @@ import subprocess
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def get_staged_diff() -> str:
|
|
5
|
-
|
|
5
|
+
staged_diff = subprocess.check_output(['git', 'diff', '--cached']).decode()
|
|
6
|
+
|
|
7
|
+
return staged_diff
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
def commit(message: str) -> None:
|
|
9
11
|
subprocess.run(['git', 'commit', '-m', message])
|
|
12
|
+
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: git-commit-msg-ai
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: AI-powered git commit message generator following Conventional Commits
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Requires-Python: >=3.9
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: anthropic
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: mypy; extra == "dev"
|
|
11
|
+
Requires-Dist: ruff; extra == "dev"
|
|
9
12
|
|
|
10
13
|
# git-commit-msg-ai
|
|
11
14
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
git_commit_msg_ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
git_commit_msg_ai/ai_client.py,sha256=uSqGxQihITI-4OcZ7jcZnsm7SoZfSJCPIAo5MPENqtM,1262
|
|
3
|
+
git_commit_msg_ai/cli.py,sha256=hiSvdBXYgNb9NuWSzWpTe6F3WqyiWLfauL3vTYHoh2c,662
|
|
4
|
+
git_commit_msg_ai/editor.py,sha256=gNhHrDlMNl650tunwKwhS4i2IWoKMEbwMLY3NyGrim0,518
|
|
5
|
+
git_commit_msg_ai/git_ops.py,sha256=ebTvWg1mUnXrEpup0XZaQ1jMv_JeQtFu-CpUuldjhBg,244
|
|
6
|
+
git_commit_msg_ai-1.2.0.dist-info/METADATA,sha256=gLF-4BqEjBahtHkDNHWHmQ1YsGMqdHLDa4X70uGjk1w,1926
|
|
7
|
+
git_commit_msg_ai-1.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
git_commit_msg_ai-1.2.0.dist-info/entry_points.txt,sha256=KTu6wUhl0p3nf27k8L4vpSH_hpeRQpwzMPSmKv7K5Cs,65
|
|
9
|
+
git_commit_msg_ai-1.2.0.dist-info/top_level.txt,sha256=XYQC2BXvrcREGKEG7sm9nbwO7ifqcUSVgU7SW8BTURs,18
|
|
10
|
+
git_commit_msg_ai-1.2.0.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
git_commit_msg_ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
git_commit_msg_ai/ai_client.py,sha256=A6EukpLUldU5IZRCajIQwex06vpZSdioJTiR-1HqfU0,1067
|
|
3
|
-
git_commit_msg_ai/cli.py,sha256=t0MMBmGmclGOKVQZi8IqexZfinrHKpWBmqwli0mwDKo,559
|
|
4
|
-
git_commit_msg_ai/editor.py,sha256=P5I2HQIdsoZCc5PuUdE6CvpepenWYJTieVkONzPgLCs,384
|
|
5
|
-
git_commit_msg_ai/git_ops.py,sha256=s6i0JPjQAXfBkX41KPk4oXbRhLyK-HtIFzMF3dQouv0,212
|
|
6
|
-
git_commit_msg_ai-1.1.0.dist-info/METADATA,sha256=BenF9whnrOE4pLFVk33c71BD_C6S2qFjW0QhY5BoETw,1831
|
|
7
|
-
git_commit_msg_ai-1.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
-
git_commit_msg_ai-1.1.0.dist-info/entry_points.txt,sha256=KTu6wUhl0p3nf27k8L4vpSH_hpeRQpwzMPSmKv7K5Cs,65
|
|
9
|
-
git_commit_msg_ai-1.1.0.dist-info/top_level.txt,sha256=XYQC2BXvrcREGKEG7sm9nbwO7ifqcUSVgU7SW8BTURs,18
|
|
10
|
-
git_commit_msg_ai-1.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|