From e27502a1d3f24418e556603bfa3a1593f25f01e8 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Mon, 29 Jan 2024 21:42:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AD=89=E5=BE=85=E4=B8=80=E5=88=86?= =?UTF-8?q?=E9=92=9F=E5=86=8D=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/publish/__init__.py | 4 ++++ tests/publish/process/test_pull_request.py | 26 +++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/plugins/publish/__init__.py b/src/plugins/publish/__init__.py index de64f339..ce105afc 100644 --- a/src/plugins/publish/__init__.py +++ b/src/plugins/publish/__init__.py @@ -1,3 +1,5 @@ +import asyncio + from nonebot import logger, on_type from nonebot.adapters.github import ( GitHubBot, @@ -118,6 +120,8 @@ async def handle_pr_close( else: logger.info("发布的拉取请求未合并,已跳过") + # GitHub 的缓存一般 1 分钟左右会刷新 + await asyncio.sleep(60) # 如果商店更新则触发 registry 更新 if event.payload.pull_request.merged: await trigger_registry_update(bot, repo_info, publish_type, issue) diff --git a/tests/publish/process/test_pull_request.py b/tests/publish/process/test_pull_request.py index 423a2348..a72f071a 100644 --- a/tests/publish/process/test_pull_request.py +++ b/tests/publish/process/test_pull_request.py @@ -17,6 +17,7 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None: event_path = Path(__file__).parent.parent / "events" / "pr-close.json" mock_subprocess_run = mocker.patch("subprocess.run") + mock_sleep = mocker.patch("asyncio.sleep") mock_issue = mocker.MagicMock() mock_issue.state = "open" @@ -73,6 +74,11 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None: }, True, ) + ctx.should_call_api( + "rest.pulls.async_list", + {"owner": "he0119", "repo": "action-test", "state": "open"}, + mock_pulls_resp, + ) ctx.should_call_api( "rest.issues.async_list_comments", {"owner": "he0119", "repo": "action-test", "issue_number": 80}, @@ -92,11 +98,6 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None: }, True, ) - ctx.should_call_api( - "rest.pulls.async_list", - {"owner": "he0119", "repo": "action-test", "state": "open"}, - mock_pulls_resp, - ) ctx.receive_event(bot, event) @@ -117,6 +118,8 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None: any_order=True, ) + mock_sleep.assert_awaited_once_with(60) + async def test_process_pull_request_not_merged(app: App, mocker: MockerFixture) -> None: from src.plugins.publish import pr_close_matcher @@ -199,6 +202,7 @@ async def test_process_pull_request_skip_plugin_test( event_path = Path(__file__).parent.parent / "events" / "pr-close.json" mock_subprocess_run = mocker.patch("subprocess.run") + mock_sleep = mocker.patch("asyncio.sleep") mock_issue = mocker.MagicMock() mock_issue.state = "open" @@ -257,6 +261,11 @@ async def test_process_pull_request_skip_plugin_test( }, True, ) + ctx.should_call_api( + "rest.pulls.async_list", + {"owner": "he0119", "repo": "action-test", "state": "open"}, + mock_pulls_resp, + ) ctx.should_call_api( "rest.issues.async_list_comments", {"owner": "he0119", "repo": "action-test", "issue_number": 80}, @@ -277,11 +286,6 @@ async def test_process_pull_request_skip_plugin_test( }, True, ) - ctx.should_call_api( - "rest.pulls.async_list", - {"owner": "he0119", "repo": "action-test", "state": "open"}, - mock_pulls_resp, - ) ctx.receive_event(bot, event) @@ -302,6 +306,8 @@ async def test_process_pull_request_skip_plugin_test( any_order=True, ) + mock_sleep.assert_awaited_once_with(60) + async def test_not_publish(app: App, mocker: MockerFixture) -> None: """测试与发布无关的拉取请求"""