diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e1cd0b..609fc64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ ## [Unreleased] +### Fixed + +- 等待 2 分钟后再触发 registry_update + ## [3.2.0] - 2023-10-21 ### Added diff --git a/src/plugins/publish/__init__.py b/src/plugins/publish/__init__.py index 15b78154..b38206ee 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, @@ -95,12 +97,6 @@ async def handle_pr_close( ) logger.info(f"议题 #{related_issue_number} 已关闭") - # 如果商店更新则触发 registry 更新 - if event.payload.pull_request.merged: - await trigger_registry_update(bot, repo_info, publish_type, issue) - else: - logger.info("拉取请求未合并,跳过触发商店列表更新") - try: run_shell_command( [ @@ -124,6 +120,14 @@ async def handle_pr_close( else: logger.info("发布的拉取请求未合并,已跳过") + # 如果商店更新则触发 registry 更新 + if event.payload.pull_request.merged: + # GitHub 的缓存一般 2 分钟左右会刷新 + await asyncio.sleep(120) + await trigger_registry_update(bot, repo_info, publish_type, issue) + else: + logger.info("拉取请求未合并,跳过触发商店列表更新") + async def check_rule( event: IssuesOpened | IssuesReopened | IssuesEdited | IssueCommentCreated, diff --git a/tests/publish/process/test_pull_request.py b/tests/publish/process/test_pull_request.py index 423a2348..aaa3ff02 100644 --- a/tests/publish/process/test_pull_request.py +++ b/tests/publish/process/test_pull_request.py @@ -17,6 +17,8 @@ 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_sleep.return_value = None mock_issue = mocker.MagicMock() mock_issue.state = "open" @@ -73,6 +75,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 +99,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 +119,8 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None: any_order=True, ) + mock_sleep.assert_awaited_once_with(120) + async def test_process_pull_request_not_merged(app: App, mocker: MockerFixture) -> None: from src.plugins.publish import pr_close_matcher @@ -199,6 +203,8 @@ 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_sleep.return_value = None mock_issue = mocker.MagicMock() mock_issue.state = "open" @@ -257,6 +263,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 +288,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 +308,8 @@ async def test_process_pull_request_skip_plugin_test( any_order=True, ) + mock_sleep.assert_awaited_once_with(120) + async def test_not_publish(app: App, mocker: MockerFixture) -> None: """测试与发布无关的拉取请求"""