Skip to content

Commit

Permalink
fix: 修复 registry_update 没法正常触发的问题 (#285)
Browse files Browse the repository at this point in the history
* chore: 添加一些调试信息

* fix: 修复 registry_update 没法正常触发的问题

* test: 修复测试问题
  • Loading branch information
he0119 authored Nov 20, 2024
1 parent e09fd77 commit c74865d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
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

- 修复 registry_update 没法正常触发的问题

## [4.0.9] - 2024-11-20

### Fixed
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/github/plugins/publish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,25 @@ async def trigger_registry_update(handler: IssueHandler, publish_type: PublishTy
issue = handler.issue

# 重新验证信息
# 这个时候已经合并了发布信息,如果还加载之前的数据则会报错重复
# 所以这里不能加载之前的数据
match publish_type:
case PublishType.ADAPTER:
result = await validate_adapter_info_from_issue(issue)
result = await validate_adapter_info_from_issue(
issue, load_previous_data=False
)
case PublishType.BOT:
result = await validate_bot_info_from_issue(issue)
result = await validate_bot_info_from_issue(issue, load_previous_data=False)
case PublishType.PLUGIN:
result = await validate_plugin_info_from_issue(handler)
result = await validate_plugin_info_from_issue(
handler, load_previous_data=False
)
case _:
raise ValueError("暂不支持的发布类型")

if not result.valid or not result.info:
logger.error("信息验证失败,跳过触发商店列表更新")
logger.debug(f"验证结果: {result}")
return

# 触发商店列表更新
Expand Down
31 changes: 25 additions & 6 deletions src/plugins/github/plugins/publish/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def add_step_summary(summary: str):


async def validate_plugin_info_from_issue(
handler: IssueHandler, skip_test: bool | None = None
handler: IssueHandler,
skip_test: bool | None = None,
load_previous_data: bool = True,
) -> ValidationDict:
"""从议题中获取插件信息,并且运行插件测试加载且获取插件元信息后进行验证"""
body = handler.issue.body if handler.issue.body else ""
Expand All @@ -71,7 +73,11 @@ async def validate_plugin_info_from_issue(
test_config: str = raw_data.get("test_config", "")

# 获取插件上次的数据
previous_data = load_json_from_file(plugin_config.input_config.plugin_path)
previous_data = (
load_json_from_file(plugin_config.input_config.plugin_path)
if load_previous_data
else []
)

# 决定是否跳过插件测试
# 因为在上一步可能已经知道了是否跳过插件测试,所以这里可以传入
Expand Down Expand Up @@ -144,7 +150,9 @@ async def validate_plugin_info_from_issue(
return result


async def validate_adapter_info_from_issue(issue: Issue) -> ValidationDict:
async def validate_adapter_info_from_issue(
issue: Issue, load_previous_data: bool = True
) -> ValidationDict:
"""从议题中提取适配器信息"""
body = issue.body if issue.body else ""
raw_data: dict[str, Any] = extract_issue_info_from_issue(
Expand All @@ -160,12 +168,19 @@ async def validate_adapter_info_from_issue(issue: Issue) -> ValidationDict:
)
raw_data.update(AuthorInfo.from_issue(issue).model_dump())

previous_data = load_json_from_file(plugin_config.input_config.adapter_path)
previous_data = (
load_json_from_file(plugin_config.input_config.adapter_path)
if load_previous_data
else []
)

return validate_info(PublishType.ADAPTER, raw_data, previous_data)


async def validate_bot_info_from_issue(issue: Issue) -> ValidationDict:
async def validate_bot_info_from_issue(
issue: Issue,
load_previous_data: bool = True,
) -> ValidationDict:
"""从议题中提取机器人信息"""
body = issue.body if issue.body else ""
raw_data: dict[str, Any] = extract_issue_info_from_issue(
Expand All @@ -180,6 +195,10 @@ async def validate_bot_info_from_issue(issue: Issue) -> ValidationDict:

raw_data.update(AuthorInfo.from_issue(issue).model_dump())

previous_data = load_json_from_file(plugin_config.input_config.bot_path)
previous_data = (
load_json_from_file(plugin_config.input_config.bot_path)
if load_previous_data
else []
)

return validate_info(PublishType.BOT, raw_data, previous_data)
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def mocked_api(respx_mock: MockRouter):
)
respx_mock.get("https://www.baidu.com", name="homepage_failed").respond(404)
respx_mock.get("https://nonebot.dev/", name="homepage").respond()
respx_mock.get("https://v2.nonebot.dev", name="homepage_v2").respond()
respx_mock.get(STORE_ADAPTERS_URL, name="store_adapters").respond(
json=[
{
Expand Down
9 changes: 6 additions & 3 deletions tests/github/publish/utils/test_trigger_registry_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ async def test_trigger_registry_update_skip_test(


async def test_trigger_registry_update_bot(app: App, mocker: MockerFixture):
"""机器人发布的情况"""
"""机器人发布的情况
已经有相同机器人的时候,registry_update 不会影响到机器人的测试
"""
from src.plugins.github.models import IssueHandler, RepoInfo
from src.plugins.github.plugins.publish.utils import trigger_registry_update
from src.providers.validation import PublishType

mock_issue = MockIssue(
body=MockBody(type="bot").generate(),
body=MockBody(type="bot", homepage="https://v2.nonebot.dev").generate(),
number=1,
).as_mock(mocker)

Expand All @@ -243,7 +246,7 @@ async def test_trigger_registry_update_bot(app: App, mocker: MockerFixture):
"name": "name",
"desc": "desc",
"author": "test",
"homepage": "https://nonebot.dev",
"homepage": "https://v2.nonebot.dev",
"tags": [{"label": "test", "color": "#ffffff"}],
"is_official": False,
},
Expand Down

0 comments on commit c74865d

Please sign in to comment.