From d50366450fb1f8ad611a853eb4cc48dab33dd720 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Wed, 23 Aug 2023 14:41:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=87=E6=8D=A2=E5=88=86=E6=94=AF?= =?UTF-8?q?=E5=89=8D=E8=BF=98=E9=9C=80=E8=A6=81=E8=8E=B7=E5=8F=96=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/publish/__init__.py | 4 ---- src/plugins/publish/utils.py | 2 ++ tests/publish/process/test_auto_merge.py | 5 ----- tests/publish/utils/test_resolve_conflict_pull_requests.py | 3 +++ 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/plugins/publish/__init__.py b/src/plugins/publish/__init__.py index fa8c2814..a2082da9 100644 --- a/src/plugins/publish/__init__.py +++ b/src/plugins/publish/__init__.py @@ -270,10 +270,6 @@ async def handle_auto_merge( ).parsed_data if not pull_request.mergeable: - # 需要先获取远程分支,否则无法切换到对应分支 - run_shell_command( - ["git", "fetch", "origin", plugin_config.input_config.base] - ) # 尝试处理冲突 await resolve_conflict_pull_requests([pull_request]) diff --git a/src/plugins/publish/utils.py b/src/plugins/publish/utils.py index 80ed9ab9..6b0254da 100644 --- a/src/plugins/publish/utils.py +++ b/src/plugins/publish/utils.py @@ -275,6 +275,8 @@ async def resolve_conflict_pull_requests( publish_type = get_type_by_labels(pull.labels) if publish_type: + # 需要先获取远程分支,否则无法切换到对应分支 + run_shell_command(["git", "fetch", "origin"]) # 因为当前分支为触发处理冲突的分支,所以需要切换到每个拉取请求对应的分支 run_shell_command(["git", "checkout", pull.head.ref]) # 获取数据 diff --git a/tests/publish/process/test_auto_merge.py b/tests/publish/process/test_auto_merge.py index f750815f..6d641a53 100644 --- a/tests/publish/process/test_auto_merge.py +++ b/tests/publish/process/test_auto_merge.py @@ -158,11 +158,6 @@ async def test_auto_merge_need_rebase(app: App, mocker: MockerFixture) -> None: ["git", "config", "--global", "safe.directory", "*"], check=True, capture_output=True, - ), - mocker.call( - ["git", "fetch", "origin", "master"], - check=True, - capture_output=True, ), # type: ignore ], any_order=True, diff --git a/tests/publish/utils/test_resolve_conflict_pull_requests.py b/tests/publish/utils/test_resolve_conflict_pull_requests.py index b4518024..b5c25203 100644 --- a/tests/publish/utils/test_resolve_conflict_pull_requests.py +++ b/tests/publish/utils/test_resolve_conflict_pull_requests.py @@ -65,6 +65,7 @@ async def test_resolve_conflict_pull_requests_adapter( # 测试 git 命令 mock_subprocess_run.assert_has_calls( [ + mocker.call(["git", "fetch", "origin"], check=True, capture_output=True), mocker.call( ["git", "checkout", "publish/issue1"], check=True, capture_output=True ), @@ -188,6 +189,7 @@ async def test_resolve_conflict_pull_requests_bot( # 测试 git 命令 mock_subprocess_run.assert_has_calls( [ + mocker.call(["git", "fetch", "origin"], check=True, capture_output=True), mocker.call( ["git", "checkout", "publish/issue1"], check=True, capture_output=True ), @@ -311,6 +313,7 @@ async def test_resolve_conflict_pull_requests_plugin( # 测试 git 命令 mock_subprocess_run.assert_has_calls( [ + mocker.call(["git", "fetch", "origin"], check=True, capture_output=True), mocker.call( ["git", "checkout", "publish/issue1"], check=True, capture_output=True ),