From 083c714ac0834b578a161caa503198b534a482fa Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Fri, 7 Mar 2025 13:02:06 +0800 Subject: [PATCH] style: improve code formatting and whitespace - Remove trailing whitespaces in Step class - Improve formatting in GitHub and GitLab commit modules - Fix indentation in error message output - Add proper line spacing between functions --- lib/chatmark/step.py | 1 - merico/github/commit/commit.py | 24 +++++++++++++++--------- merico/gitlab/commit/commit.py | 24 +++++++++++++++--------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/chatmark/step.py b/lib/chatmark/step.py index 4d839dc..1700d14 100644 --- a/lib/chatmark/step.py +++ b/lib/chatmark/step.py @@ -34,4 +34,3 @@ class Step(AbstractContextManager): IDEService().ide_logging( "debug", f"Step {self.title} took {end_time - self.enter_time:.2f} seconds" ) - diff --git a/merico/github/commit/commit.py b/merico/github/commit/commit.py index baaa0ef..44d520a 100644 --- a/merico/github/commit/commit.py +++ b/merico/github/commit/commit.py @@ -358,36 +358,41 @@ def check_git_installed(): 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.", end="\n\n", file=sys.stderr, flush=True) + print( + "Could not determine current branch. Push failed.", + end="\n\n", + file=sys.stderr, + flush=True, + ) return False - + print(f"Pushing changes to origin/{current_branch}...", end="\n\n", flush=True) result = subprocess_run( ["git", "push", "origin", current_branch], @@ -408,6 +413,7 @@ def push_changes(): print(f"An unexpected error occurred: {str(e)}", end="\n\n", file=sys.stderr, flush=True) return False + def main(): global language try: @@ -476,7 +482,7 @@ def main(): if not push_changes(): print("Push failed.", flush=True) sys.exit(-1) - + print("Commit completed.", flush=True) sys.exit(0) except Exception as err: diff --git a/merico/gitlab/commit/commit.py b/merico/gitlab/commit/commit.py index 493f4b2..8f0d57c 100644 --- a/merico/gitlab/commit/commit.py +++ b/merico/gitlab/commit/commit.py @@ -358,36 +358,41 @@ def check_git_installed(): 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.", end="\n\n", file=sys.stderr, flush=True) + print( + "Could not determine current branch. Push failed.", + end="\n\n", + file=sys.stderr, + flush=True, + ) return False - + print(f"Pushing changes to origin/{current_branch}...", end="\n\n", flush=True) result = subprocess_run( ["git", "push", "origin", current_branch], @@ -408,6 +413,7 @@ def push_changes(): print(f"An unexpected error occurred: {str(e)}", end="\n\n", file=sys.stderr, flush=True) return False + def main(): global language try: @@ -476,7 +482,7 @@ def main(): if not push_changes(): print("Push failed.", flush=True) sys.exit(-1) - + print("Commit completed.", flush=True) sys.exit(0) except Exception as err: