-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_name_per_git_diff.py
More file actions
33 lines (30 loc) · 1.4 KB
/
commit_name_per_git_diff.py
File metadata and controls
33 lines (30 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
import subprocess
from async_openai_client import AsyncOpenAIClient
async def generate_commit_message(changes):
client = AsyncOpenAIClient()
while True:
prompt = "You're an expert developer, generate a short commit message with one emoji at the beginning for the following changes: \n\n ```" + changes + "```"
commit_message = await client.generate_response(prompt)
print(commit_message)
# Confirm the commit message
confirm = input("\n\n Is this commit message okay? (Y/n): ")
if confirm.lower() in ['y', 'yes']:
# Execute Git commands
subprocess.run(["git", "add", "."])
subprocess.run(["git", "commit", "-m", commit_message])
break # Exit loop after successful commit
else:
# Ask for user input and use it as the new changes description
print("Please provide a custom commit description.")
changes = input("Commit description: ")
if __name__ == "__main__":
try:
# Execute git diff and capture its output
git_diff_output = subprocess.check_output(["git", "diff"], text=True)
if git_diff_output:
asyncio.run(generate_commit_message(git_diff_output))
else:
print("No changes detected.")
except subprocess.CalledProcessError as e:
print("An error occurred while trying to get git diff:", e)