feat(scripts): modify gen_commit.py to enhance commit message generation

This commit is contained in:
2025-05-14 09:03:13 +07:00
parent 93f42839f9
commit 86eeef2a72
2 changed files with 50 additions and 17 deletions
+28 -17
View File
@@ -39,23 +39,34 @@ def gen_commit(project_path):
"""Use OpenInterpreter to generate a commit message based on git diff."""
agent = OpenInterpreter()
agent.auto_run = True
with open(
os.path.join(os.path.dirname(__file__), "resources/commit_convention.md"),
"r",
) as f:
file_content = f.read()
agent.system_message = f"""
# Read both convention and git commit files
convention_path = os.path.join(
os.path.dirname(__file__), "resources/commit_convention.md"
)
git_commit_path = os.path.join(os.path.dirname(__file__), "resources/git_commit.md")
with open(convention_path, "r") as f:
convention_content = f.read()
with open(git_commit_path, "r") as f:
git_commit_content = f.read()
agent.system_message = f"""
Your name is Bifrost.
You are a helpful assistant that generates commit messages based on uncommitted code.
Follow these rules:
1. Use English.
2. Be concise and follow this format:
{file_content}
3. Only return the commit message. Do not add explanation or extra output.
"""
{convention_content}
3. Use these git commands to analyze changes as you see fit:
{git_commit_content}
4. Only return the commit message. Do not add explanation or extra output.
"""
prompt = f"""
prompt = f"""
Generate a commit message based on the following changes in the project directory:
First, change directory:
@@ -65,16 +76,16 @@ def gen_commit(project_path):
git diff --name-status
Then generate a commit message according to the changes.
"""
"""
response = agent.chat(prompt)
response = agent.chat(prompt)
# Extract just the content from the response
if isinstance(response, list) and len(response) > 0:
if isinstance(response[-1], dict) and "content" in response[-1]:
return response[-1]["content"].strip()
# Extract just the content from the response
if isinstance(response, list) and len(response) > 0:
if isinstance(response[-1], dict) and "content" in response[-1]:
return response[-1]["content"].strip()
return str(response).strip()
return str(response).strip()
def push_code():
@@ -0,0 +1,22 @@
How to show uncommitted changes in Git
The command you are looking for is git diff.
git diff - Show changes between commits, commit and working tree, etc
Here are some of the options it expose which you can use
git diff (no parameters)
Print out differences between your working directory and the index.
git diff --cached:
Print out differences between the index and HEAD (current commit).
git diff HEAD:
Print out differences between your working directory and the HEAD.
git diff --name-only
Show only names of changed files.
git diff --name-status
Show only names and status of changed files.