feat(scripts): modify gen_commit.py to enhance commit message generation
This commit is contained in:
@@ -39,23 +39,34 @@ def gen_commit(project_path):
|
|||||||
"""Use OpenInterpreter to generate a commit message based on git diff."""
|
"""Use OpenInterpreter to generate a commit message based on git diff."""
|
||||||
agent = OpenInterpreter()
|
agent = OpenInterpreter()
|
||||||
agent.auto_run = True
|
agent.auto_run = True
|
||||||
with open(
|
|
||||||
os.path.join(os.path.dirname(__file__), "resources/commit_convention.md"),
|
# Read both convention and git commit files
|
||||||
"r",
|
convention_path = os.path.join(
|
||||||
) as f:
|
os.path.dirname(__file__), "resources/commit_convention.md"
|
||||||
file_content = f.read()
|
)
|
||||||
agent.system_message = f"""
|
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.
|
Your name is Bifrost.
|
||||||
You are a helpful assistant that generates commit messages based on uncommitted code.
|
You are a helpful assistant that generates commit messages based on uncommitted code.
|
||||||
|
|
||||||
Follow these rules:
|
Follow these rules:
|
||||||
1. Use English.
|
1. Use English.
|
||||||
2. Be concise and follow this format:
|
2. Be concise and follow this format:
|
||||||
{file_content}
|
{convention_content}
|
||||||
3. Only return the commit message. Do not add explanation or extra output.
|
|
||||||
"""
|
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:
|
Generate a commit message based on the following changes in the project directory:
|
||||||
|
|
||||||
First, change directory:
|
First, change directory:
|
||||||
@@ -65,16 +76,16 @@ def gen_commit(project_path):
|
|||||||
git diff --name-status
|
git diff --name-status
|
||||||
|
|
||||||
Then generate a commit message according to the changes.
|
Then generate a commit message according to the changes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = agent.chat(prompt)
|
response = agent.chat(prompt)
|
||||||
|
|
||||||
# Extract just the content from the response
|
# Extract just the content from the response
|
||||||
if isinstance(response, list) and len(response) > 0:
|
if isinstance(response, list) and len(response) > 0:
|
||||||
if isinstance(response[-1], dict) and "content" in response[-1]:
|
if isinstance(response[-1], dict) and "content" in response[-1]:
|
||||||
return response[-1]["content"].strip()
|
return response[-1]["content"].strip()
|
||||||
|
|
||||||
return str(response).strip()
|
return str(response).strip()
|
||||||
|
|
||||||
|
|
||||||
def push_code():
|
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.
|
||||||
Reference in New Issue
Block a user