Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 等待 2 分钟后再触发 registry_update #197

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

from nonebot import logger, on_type
from nonebot.adapters.github import (
GitHubBot,
Expand Down Expand Up @@ -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(
[
Expand All @@ -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,
Expand Down
28 changes: 18 additions & 10 deletions tests/publish/process/test_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand All @@ -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)

Expand All @@ -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:
"""测试与发布无关的拉取请求"""
Expand Down
Loading