Skip to content
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
11 changes: 4 additions & 7 deletions src/plugins/github/plugins/publish/validation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import re
from typing import Any

Expand All @@ -11,6 +10,7 @@
from src.plugins.github.utils import extract_issue_info_from_issue
from src.providers.constants import DOCKER_IMAGES
from src.providers.docker_test import DockerPluginTest, Metadata
from src.providers.utils import load_json5_from_file
from src.providers.validation import PublishType, ValidationDict, validate_info

from .constants import (
Expand Down Expand Up @@ -65,8 +65,7 @@ async def validate_plugin_info_from_issue(
test_config: str = raw_data.get("test_config", "")

# 获取插件上次的数据
with plugin_config.input_config.plugin_path.open("r", encoding="utf-8") as f:
previous_data: list[dict[str, Any]] = json.load(f)
previous_data = load_json5_from_file(plugin_config.input_config.plugin_path)

# 决定是否跳过插件测试
# 因为在上一步可能已经知道了是否跳过插件测试,所以这里可以传入
Expand Down Expand Up @@ -148,8 +147,7 @@ async def validate_adapter_info_from_issue(issue: Issue) -> ValidationDict:
)
raw_data.update(AuthorInfo.from_issue(issue).model_dump())

with plugin_config.input_config.adapter_path.open("r", encoding="utf-8") as f:
previous_data: list[dict[str, str]] = json.load(f)
previous_data = load_json5_from_file(plugin_config.input_config.adapter_path)

return validate_info(PublishType.ADAPTER, raw_data, previous_data)

Expand All @@ -169,7 +167,6 @@ async def validate_bot_info_from_issue(issue: Issue) -> ValidationDict:

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

with plugin_config.input_config.bot_path.open("r", encoding="utf-8") as f:
previous_data: list[dict[str, str]] = json.load(f)
previous_data = load_json5_from_file(plugin_config.input_config.bot_path)

return validate_info(PublishType.BOT, raw_data, previous_data)
92 changes: 45 additions & 47 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -46,53 +45,52 @@ def load_plugin(nonebug_init: None) -> set["Plugin"]:
@pytest.fixture
async def app(app: App, tmp_path: Path, mocker: MockerFixture):
from src.plugins.github import plugin_config
from src.providers.utils import dump_json5

adapter_path = tmp_path / "adapters.json"
with adapter_path.open("w") as f:
json.dump(
[
{
"module_name": "module_name1",
"project_link": "project_link1",
"name": "name",
"desc": "desc",
"author_id": 1,
"homepage": "https://v2.nonebot.dev",
"tags": [],
"is_official": False,
}
],
f,
)
bot_path = tmp_path / "bots.json"
with bot_path.open("w") as f:
json.dump(
[
{
"name": "name",
"desc": "desc",
"author_id": 1,
"homepage": "https://v2.nonebot.dev",
"tags": [],
"is_official": False,
}
],
f,
)
plugin_path = tmp_path / "plugins.json"
with plugin_path.open("w") as f:
json.dump(
[
{
"module_name": "module_name1",
"project_link": "project_link1",
"author_id": 1,
"tags": [],
"is_official": False,
}
],
f,
)
adapter_path = tmp_path / "adapters.json5"
dump_json5(
adapter_path,
[
{
"module_name": "module_name1",
"project_link": "project_link1",
"name": "name",
"desc": "desc",
"author_id": 1,
"homepage": "https://v2.nonebot.dev",
"tags": [],
"is_official": False,
}
],
)
bot_path = tmp_path / "bots.json5"
dump_json5(
bot_path,
[
{
"name": "name",
"desc": "desc",
"author_id": 1,
"homepage": "https://v2.nonebot.dev",
"tags": [],
"is_official": False,
}
],
)

plugin_path = tmp_path / "plugins.json5"
dump_json5(
plugin_path,
[
{
"module_name": "module_name1",
"project_link": "project_link1",
"author_id": 1,
"tags": [],
"is_official": False,
}
],
)

mocker.patch.object(plugin_config.input_config, "adapter_path", adapter_path)
mocker.patch.object(plugin_config.input_config, "bot_path", bot_path)
Expand Down
16 changes: 8 additions & 8 deletions tests/github/publish/process/test_publish_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_bot_process_publish_check(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = mock_pull

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down Expand Up @@ -245,7 +245,7 @@ async def test_adapter_process_publish_check(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = mock_pull

with open(tmp_path / "adapters.json", "w") as f:
with open(tmp_path / "adapters.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.adapter_path, [])
Expand Down Expand Up @@ -458,7 +458,7 @@ async def test_edit_title(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = [mock_pull]

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down Expand Up @@ -678,7 +678,7 @@ async def test_edit_title_too_long(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = []

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down Expand Up @@ -809,7 +809,7 @@ async def test_process_publish_check_not_pass(
mock_list_comments_resp = mocker.MagicMock()
mock_list_comments_resp.parsed_data = [mock_comment]

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down Expand Up @@ -1057,7 +1057,7 @@ async def test_skip_plugin_check(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = []

with open(tmp_path / "plugins.json", "w") as f:
with open(tmp_path / "plugins.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.plugin_path, [])
Expand Down Expand Up @@ -1261,7 +1261,7 @@ async def test_convert_pull_request_to_draft(
mock_list_comments_resp = mocker.MagicMock()
mock_list_comments_resp.parsed_data = [mock_comment]

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down Expand Up @@ -1404,7 +1404,7 @@ async def test_process_publish_check_ready_for_review(
mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = [mock_pull]

with open(tmp_path / "bots.json", "w") as f:
with open(tmp_path / "bots.json5", "w") as f:
json.dump([], f)

check_json_data(plugin_config.input_config.bot_path, [])
Expand Down
Loading
Loading