Skip to content

Commit

Permalink
fix: 切换分支前还需要获取远程分支
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Aug 23, 2023
1 parent 35a7328 commit d503664
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/publish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
# 获取数据
Expand Down
5 changes: 0 additions & 5 deletions tests/publish/process/test_auto_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/publish/utils/test_resolve_conflict_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down Expand Up @@ -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
),
Expand Down Expand Up @@ -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
),
Expand Down

0 comments on commit d503664

Please sign in to comment.