AI-Powered Git Commit Message Generator

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/askrobots_commitgen.git
HTTPS
https://gitstable.com/git/askrobots/askrobots_commitgen.git
SSH
ssh://git@gitstable.com:2222/askrobots/askrobots_commitgen.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Create commit message adjusting OpenAI initialization and error handling. c0d2e25 2 years, 6 months ago History
main.py · 981 bytes · 34 lines
1import sys
2import subprocess
3from git_operations import get_git_diff
4from ai_commit import generate_commit_message
5
6def commit_changes(commit_message):
7 try:
8 subprocess.run(["git", "commit", "-m", commit_message], check=True)
9 print(f"Changes committed with message: {commit_message}")
10 except subprocess.CalledProcessError as e:
11 print(f"Error during git commit: {e}")
12 return
13
14def main():
15 # Check if only displaying the message or also committing
16 only_show_message = "--show-only" in sys.argv
17
18 diff = get_git_diff()
19 if not diff:
20 print("No changes detected.")
21 return
22
23 commit_message = generate_commit_message(diff)
24 if commit_message:
25 if only_show_message:
26 print("Generated commit message:")
27 print(commit_message)
28 else:
29 commit_changes(commit_message)
30 else:
31 print("Failed to generate a commit message.")
32
33if __name__ == "__main__":
34 main()