feat: Add push functionality to commit workflow
- Fixed Step markdown formatting in chatmark/step.py - Added push capability with user confirmation after commit - Improved command line argument handling with better defaults
This commit is contained in:
parent
f4a4dbc529
commit
90d7e0b7b9
@ -26,6 +26,7 @@ class Step(AbstractContextManager):
|
||||
|
||||
def __enter__(self):
|
||||
print(f"\n```Step\n# {self.title}", flush=True)
|
||||
print("\n```", flush=True)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
# close the step
|
||||
@ -33,4 +34,4 @@ class Step(AbstractContextManager):
|
||||
IDEService().ide_logging(
|
||||
"debug", f"Step {self.title} took {end_time - self.enter_time:.2f} seconds"
|
||||
)
|
||||
print("\n```", flush=True)
|
||||
|
||||
|
@ -6,7 +6,7 @@ import sys
|
||||
|
||||
from devchat.llm import chat_completion_stream
|
||||
|
||||
from lib.chatmark import Checkbox, Form, TextEditor
|
||||
from lib.chatmark import Button, Checkbox, Form, TextEditor
|
||||
from lib.ide_service import IDEService
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
|
||||
@ -355,23 +355,66 @@ def check_git_installed():
|
||||
return False
|
||||
|
||||
|
||||
def ask_for_push():
|
||||
"""
|
||||
询问用户是否要推送(push)更改到远程仓库
|
||||
|
||||
Returns:
|
||||
bool: 用户是否选择推送
|
||||
"""
|
||||
from lib.chatmark import Button
|
||||
|
||||
print(
|
||||
"Step 3/3: Would you like to push your commit to the remote repository?",
|
||||
end="\n\n",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
button = Button(["Yes, push now", "No, I'll push later"])
|
||||
button.render()
|
||||
|
||||
return button.clicked == 0 # 如果用户点击第一个按钮(Yes),则返回True
|
||||
|
||||
def push_changes():
|
||||
"""
|
||||
推送更改到远程仓库
|
||||
|
||||
Returns:
|
||||
bool: 推送是否成功
|
||||
"""
|
||||
try:
|
||||
current_branch = get_current_branch()
|
||||
if not current_branch:
|
||||
print("Could not determine current branch. Push failed.", file=sys.stderr, flush=True)
|
||||
return False
|
||||
|
||||
print(f"Pushing changes to origin/{current_branch}...", flush=True)
|
||||
result = subprocess_check_output(["git", "push", "origin", current_branch])
|
||||
print("Push completed successfully.", flush=True)
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Push failed: {str(e)}", file=sys.stderr, flush=True)
|
||||
return False
|
||||
|
||||
def main():
|
||||
global language
|
||||
try:
|
||||
print("Let's follow the steps below.\n\n")
|
||||
# Ensure enough command line arguments are provided
|
||||
if len(sys.argv) < 3:
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python script.py <user_input> <language>", file=sys.stderr, flush=True)
|
||||
sys.exit(-1)
|
||||
|
||||
user_input = sys.argv[1]
|
||||
language = sys.argv[2]
|
||||
language = "english"
|
||||
if len(sys.argv) > 2:
|
||||
language = sys.argv[2]
|
||||
|
||||
if not check_git_installed():
|
||||
sys.exit(-1)
|
||||
|
||||
print(
|
||||
"Step 1/2: Select the files you've changed that you wish to include in this commit, "
|
||||
"Step 1/3: Select the files you've changed that you wish to include in this commit, "
|
||||
"then click 'Submit'.",
|
||||
end="\n\n",
|
||||
flush=True,
|
||||
@ -389,7 +432,7 @@ def main():
|
||||
rebuild_stage_list(selected_files)
|
||||
|
||||
print(
|
||||
"Step 2/2: Review the commit message I've drafted for you. "
|
||||
"Step 2/3: Review the commit message I've drafted for you. "
|
||||
"Edit it below if needed. Then click 'Commit' to proceed with "
|
||||
"the commit using this message.",
|
||||
end="\n\n",
|
||||
@ -416,6 +459,10 @@ def main():
|
||||
if not commit_result:
|
||||
print("Commit aborted.", flush=True)
|
||||
else:
|
||||
# 添加推送步骤
|
||||
if ask_for_push():
|
||||
push_changes()
|
||||
|
||||
print("Commit completed.", flush=True)
|
||||
sys.exit(0)
|
||||
except Exception as err:
|
||||
|
Loading…
x
Reference in New Issue
Block a user