refactor(scripts): streamline git diff usage and update commit generation logic

This commit is contained in:
KaySar12 2025-05-20 16:38:47 +07:00
parent 91c9244fdc
commit d9396a176d
2 changed files with 10 additions and 10 deletions

View File

@ -29,8 +29,13 @@ def gen_commit(project_path):
convention_path = os.path.join(
os.path.dirname(__file__), "resources/commit_convention.md"
)
git_commit_convention_path = os.path.join(
os.path.dirname(__file__), "resources/git_commit_convention.md"
)
with open(convention_path, "r") as f:
convention_content = f.read()
with open(git_commit_convention_path, "r") as f:
git_commit_convention_content = f.read()
agent.system_message = f"""
You are a helpful assistant that generates concise, conventional commit messages based on code diffs.
@ -38,19 +43,14 @@ You are a helpful assistant that generates concise, conventional commit messages
Guidelines:
- Use English.
- Do not include explanationsonly output commit message in under 100 characters.
- Follow this convention:
- Use this git commit convention to get uncommitted changes:
{git_commit_convention_content}
- After getting uncommitted changes, analyze and generate a commit message Follow this convention:
{convention_content}
- Commit Message should be in under 100 characters.
"""
diff_output = get_git_diff(project_path)
if not diff_output:
return "chore: no changes to commit"
prompt = f"""
Analyze the following git diff and generate a commit message:
{diff_output}
Analyze the git commit and generate a commit message for this project: {project_path}
"""
response = agent.chat(prompt)