Skip to content

Commit

Permalink
fix: 等待一分钟再触发
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Jan 29, 2024
1 parent b24f7b3 commit e27502a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 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 @@ -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)
Expand Down
26 changes: 16 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,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"
Expand Down Expand Up @@ -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},
Expand All @@ -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)

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

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

0 comments on commit e27502a

Please sign in to comment.