[{'role': 'assistant', 'type': 'code', 'format': 'shell', 'content': 'cd /root/dev/Bifrost && git diff --name-status'}, {'role': 'computer', 'type': 'console', 'format': 'output', 'content': '\nM\tMakefile\nM\tbackend/app/service/app.go\nM\tregistry\n'}, {'role': 'assistant', 'type': 'message', 'content': 'The files that have been modified are:\n\n- \n- \n- \n\nBased on these changes, here is a generated commit message:\n\n\n\nThis message indicates updates have been made to the specified files. If you have specific details about the changes, feel free to share them for a more tailored message.'}]

This commit is contained in:
2025-05-13 18:29:25 +07:00
parent 81d3a1ebaa
commit 3983b2902a
2 changed files with 77 additions and 0 deletions

View File

View File

@@ -0,0 +1,77 @@
from interpreter import OpenInterpreter
import os
from dotenv import load_dotenv
load_dotenv()
def gen_commit():
agent = OpenInterpreter()
# Set auto_run to True to always allow code execution
agent.auto_run = True
agent.system_message = """
Your name is Bifrost,
you are a helpful assistant that can help me generate a commit message base on umcommit code.
You should follow these rules:
1. The commit message should be in English.
2. The commit message should be concise and to the point.
3. The commit message should be formatted as follows:
- feat: add a new feature
- fix: fix a bug
- refactor: refactor the code
- chore: update the code
- perf: improve the performance
- test: add a test
- docs: update the docs
- update: update the code
- remove: remove the code
- style: style the code
- revert: revert the code
- merge: merge the code
- conflict: resolve the conflict
- other: other
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.
git diff --color-words
Word by word diff instead of line by line.
"""
response = agent.chat(
"""
Generate a commit message for the uncommit code in project path /root/dev/Bifrost
You should change working directory to /root/dev/Bifrost
"""
)
return response
def push_code():
commit_msg = gen_commit()
os.system(f'git pull https://{os.getenv("GIT_USER")}:{os.getenv("GIT_PASS")}@{os.getenv("GIT_REPO")} || true')
os.system('git add .')
os.system(f'git commit -m "{commit_msg}" || true')
os.system(f'git push https://{os.getenv("GIT_USER")}:{os.getenv("GIT_PASS")}@{os.getenv("GIT_REPO")} || true')
if __name__ == "__main__":
push_code()