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 ),