Skip to content

Commit 4de9b12

Browse files
eya46he0119
andauthored
fix: 等待 2 分钟后再触发 registry_update (#197)
* Update def handle_pr_close 先处理pr再触发registry更新 * fix: 等待一分钟再触发 * fix: 正确的 mock 函数 * fix: 要不等两分钟吧 * fix: 修复测试 --------- Co-authored-by: uy_sun <hmy0119@gmail.com>
1 parent 7ede4f5 commit 4de9b12

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- 等待 2 分钟后再触发 registry_update
13+
1014
## [3.2.0] - 2023-10-21
1115

1216
### Added

src/plugins/publish/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
13
from nonebot import logger, on_type
24
from nonebot.adapters.github import (
35
GitHubBot,
@@ -95,12 +97,6 @@ async def handle_pr_close(
9597
)
9698
logger.info(f"议题 #{related_issue_number} 已关闭")
9799

98-
# 如果商店更新则触发 registry 更新
99-
if event.payload.pull_request.merged:
100-
await trigger_registry_update(bot, repo_info, publish_type, issue)
101-
else:
102-
logger.info("拉取请求未合并,跳过触发商店列表更新")
103-
104100
try:
105101
run_shell_command(
106102
[
@@ -124,6 +120,14 @@ async def handle_pr_close(
124120
else:
125121
logger.info("发布的拉取请求未合并,已跳过")
126122

123+
# 如果商店更新则触发 registry 更新
124+
if event.payload.pull_request.merged:
125+
# GitHub 的缓存一般 2 分钟左右会刷新
126+
await asyncio.sleep(120)
127+
await trigger_registry_update(bot, repo_info, publish_type, issue)
128+
else:
129+
logger.info("拉取请求未合并,跳过触发商店列表更新")
130+
127131

128132
async def check_rule(
129133
event: IssuesOpened | IssuesReopened | IssuesEdited | IssueCommentCreated,

tests/publish/process/test_pull_request.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None:
1717
event_path = Path(__file__).parent.parent / "events" / "pr-close.json"
1818

1919
mock_subprocess_run = mocker.patch("subprocess.run")
20+
mock_sleep = mocker.patch("asyncio.sleep")
21+
mock_sleep.return_value = None
2022

2123
mock_issue = mocker.MagicMock()
2224
mock_issue.state = "open"
@@ -73,6 +75,11 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None:
7375
},
7476
True,
7577
)
78+
ctx.should_call_api(
79+
"rest.pulls.async_list",
80+
{"owner": "he0119", "repo": "action-test", "state": "open"},
81+
mock_pulls_resp,
82+
)
7683
ctx.should_call_api(
7784
"rest.issues.async_list_comments",
7885
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -92,11 +99,6 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None:
9299
},
93100
True,
94101
)
95-
ctx.should_call_api(
96-
"rest.pulls.async_list",
97-
{"owner": "he0119", "repo": "action-test", "state": "open"},
98-
mock_pulls_resp,
99-
)
100102

101103
ctx.receive_event(bot, event)
102104

@@ -117,6 +119,8 @@ async def test_process_pull_request(app: App, mocker: MockerFixture) -> None:
117119
any_order=True,
118120
)
119121

122+
mock_sleep.assert_awaited_once_with(120)
123+
120124

121125
async def test_process_pull_request_not_merged(app: App, mocker: MockerFixture) -> None:
122126
from src.plugins.publish import pr_close_matcher
@@ -199,6 +203,8 @@ async def test_process_pull_request_skip_plugin_test(
199203
event_path = Path(__file__).parent.parent / "events" / "pr-close.json"
200204

201205
mock_subprocess_run = mocker.patch("subprocess.run")
206+
mock_sleep = mocker.patch("asyncio.sleep")
207+
mock_sleep.return_value = None
202208

203209
mock_issue = mocker.MagicMock()
204210
mock_issue.state = "open"
@@ -257,6 +263,11 @@ async def test_process_pull_request_skip_plugin_test(
257263
},
258264
True,
259265
)
266+
ctx.should_call_api(
267+
"rest.pulls.async_list",
268+
{"owner": "he0119", "repo": "action-test", "state": "open"},
269+
mock_pulls_resp,
270+
)
260271
ctx.should_call_api(
261272
"rest.issues.async_list_comments",
262273
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -277,11 +288,6 @@ async def test_process_pull_request_skip_plugin_test(
277288
},
278289
True,
279290
)
280-
ctx.should_call_api(
281-
"rest.pulls.async_list",
282-
{"owner": "he0119", "repo": "action-test", "state": "open"},
283-
mock_pulls_resp,
284-
)
285291

286292
ctx.receive_event(bot, event)
287293

@@ -302,6 +308,8 @@ async def test_process_pull_request_skip_plugin_test(
302308
any_order=True,
303309
)
304310

311+
mock_sleep.assert_awaited_once_with(120)
312+
305313

306314
async def test_not_publish(app: App, mocker: MockerFixture) -> None:
307315
"""测试与发布无关的拉取请求"""

0 commit comments

Comments
 (0)