Files
bifrost-registry/scripts/interpreter/gen_commit.py
T

68 lines
2.2 KiB
Python
Executable File

from interpreter import OpenInterpreter
import os
import sys
from dotenv import load_dotenv
load_dotenv()
def get_git_credentials():
if len(sys.argv) != 4:
print("Usage: python gen_commit.py <GIT_USER> <GIT_PASS> <GIT_REPO>")
sys.exit(1)
return sys.argv[1], sys.argv[2], sys.argv[3]
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
4. Only return the commit message in markdown format, no other text or explanation.
"""
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 and use git diff --name-status to get the changes
"""
)
# Extract just the content from the response
if isinstance(response, list) and len(response) > 0:
if isinstance(response[0], dict) and 'content' in response[0]:
return response[0]['content']
return str(response)
def push_code():
git_user, git_pass, git_repo = get_git_credentials()
commit_msg = gen_commit()
os.system(f"git pull https://{git_user}:{git_pass}@{git_repo} || true")
os.system("git add .")
os.system(f'git commit -m "{commit_msg}" || true')
os.system(f"git push https://{git_user}:{git_pass}@{git_repo} || true")
if __name__ == "__main__":
push_code()