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

feat: 插件测试结果显示版本号和发布时间 #303

Merged
merged 2 commits into from
Dec 1, 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]

### Added

- 插件插件测试结果显示版本号和发布时间

### Fixed

- 修复 Docker Test 报错后仍无法运行的问题
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/github/plugins/publish/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@
"supported_adapters": "插件支持的适配器",
"metadata": "插件测试元数据",
"load": "插件是否成功加载",
"version": "插件版本号",
"time": "插件发布时间",
}
16 changes: 16 additions & 0 deletions src/plugins/github/plugins/publish/render.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -36,6 +37,17 @@ def loc_to_name(loc: list[str | int]) -> str:
return " > ".join([_loc_to_name(str(item)) for item in loc])


def key_to_name(key: str) -> str:
"""将 key 转换为可读名称"""
return _loc_to_name(key)


def format_time(time: str) -> str:
"""格式化时间"""
dt = datetime.fromisoformat(time)
return dt.strftime("%Y-%m-%d %H:%M:%S")


env = jinja2.Environment(
loader=jinja2.FileSystemLoader(Path(__file__).parent / "templates"),
enable_async=True,
Expand All @@ -48,6 +60,8 @@ def loc_to_name(loc: list[str | int]) -> str:
env.filters["tags_to_str"] = tags_to_str
env.filters["supported_adapters_to_str"] = supported_adapters_to_str
env.filters["loc_to_name"] = loc_to_name
env.filters["key_to_name"] = key_to_name
env.filters["format_time"] = format_time


async def render_comment(result: ValidationDict, reuse: bool = False) -> str:
Expand All @@ -64,6 +78,8 @@ async def render_comment(result: ValidationDict, reuse: bool = False) -> str:
"project_link",
"type",
"supported_adapters",
"time",
"version",
]

for key in data.copy():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
{%- else %}
插件 <a href="{{ value }}">加载测试</a> 通过。
{%- endif %}
{% else %}
{{ key }}: {{ value }}。
{%- elif key == "time" %}
插件发布时间:{{ value|format_time }}。
{%- else %}
{{ key|key_to_name }}: {{ value }}。
{%- endif %}
{% endmacro %}
5 changes: 1 addition & 4 deletions src/providers/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ class PluginPublishInfo(PublishInfo, PyPIMixin):
skip_test: bool
"""是否跳过插件测试"""
version: str
"""插件版本号

从 PyPI 获取或者测试中获取
"""
"""插件版本号"""
test_config: str = ""
"""插件测试配置"""
test_output: str = ""
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def mocked_api(respx_mock: MockRouter):
).respond(
json={
"info": {"name": "project_link", "version": "0.0.1"},
"urls": [{"upload_time_iso_8601": "2023-09-01T00:00:00+00:00Z"}],
"urls": [{"upload_time_iso_8601": "2023-09-01T00:00:00+00:00"}],
}
)
respx_mock.get(
"https://pypi.org/pypi/project_link//json", name="project_link/"
).respond(
json={
"info": {"name": "project_link/", "version": "0.0.1"},
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
}
)
respx_mock.get(
Expand Down Expand Up @@ -161,7 +161,7 @@ def mocked_api(respx_mock: MockRouter):
).respond(
json={
"info": {"name": "project_link1", "version": "0.5.0"},
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
}
)
respx_mock.get(
Expand All @@ -173,7 +173,7 @@ def mocked_api(respx_mock: MockRouter):
).respond(
json={
"info": {"name": "project-link-normalization", "version": "0.0.1"},
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
}
)
respx_mock.get("https://www.baidu.com", name="homepage_failed").respond(404)
Expand Down
2 changes: 1 addition & 1 deletion tests/github/config/process/test_config_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def test_process_config_check(

<details>
<summary>详情</summary>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/nonebot-plugin-treehelp/">nonebot-plugin-treehelp</a> 已发布至 PyPI。</li><li>✅ 项目 <a href="https://nonebot.dev">主页</a> 返回状态码 200。</li><li>✅ 标签: test-#ffffff。</li><li>✅ 插件类型: application。</li><li>✅ 插件支持的适配器: nonebot.adapters.onebot.v11。</li><li>✅ 插件 <a href="https://github.com/owner/repo/actions/runs/123456">加载测试</a> 通过。</li></code></pre>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/nonebot-plugin-treehelp/">nonebot-plugin-treehelp</a> 已发布至 PyPI。</li><li>✅ 插件发布时间:2021-08-01 00:00:00。</li><li>✅ 项目 <a href="https://nonebot.dev">主页</a> 返回状态码 200。</li><li>✅ 标签: test-#ffffff。</li><li>✅ 插件类型: application。</li><li>✅ 插件支持的适配器: nonebot.adapters.onebot.v11。</li><li>✅ 插件版本号: 1.0.0。</li><li>✅ 插件 <a href="https://github.com/owner/repo/actions/runs/123456">加载测试</a> 通过。</li></code></pre>
</details>

---
Expand Down
4 changes: 2 additions & 2 deletions tests/github/publish/process/test_publish_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ async def test_adapter_process_publish_check(

<details>
<summary>详情</summary>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/project_link/">project_link</a> 已发布至 PyPI。</li><li>✅ 项目 <a href="https://nonebot.dev">主页</a> 返回状态码 200。</li><li>✅ 标签: test-#ffffff。</li></code></pre>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/project_link/">project_link</a> 已发布至 PyPI。</li><li>✅ 插件发布时间:2023-09-01 00:00:00。</li><li>✅ 项目 <a href="https://nonebot.dev">主页</a> 返回状态码 200。</li><li>✅ 标签: test-#ffffff。</li></code></pre>
</details>

---
Expand Down Expand Up @@ -1228,7 +1228,7 @@ async def test_skip_plugin_check(

<details>
<summary>详情</summary>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/project_link/">project_link</a> 已发布至 PyPI。</li><li>✅ 标签: test-#ffffff。</li><li>✅ 插件 <a href="https://github.com/owner/repo/actions/runs/123456">加载测试</a> 已跳过。</li></code></pre>
<pre><code><li>✅ 项目 <a href="https://pypi.org/project/project_link/">project_link</a> 已发布至 PyPI。</li><li>✅ 插件发布时间:2023-09-01 00:00:00。</li><li>✅ 标签: test-#ffffff。</li><li>✅ 插件版本号: 0.0.1。</li><li>✅ 插件 <a href="https://github.com/owner/repo/actions/runs/123456">加载测试</a> 已跳过。</li></code></pre>
</details>

---
Expand Down
4 changes: 2 additions & 2 deletions tests/github/publish/process/test_publish_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def test_process_pull_request(
"type": "application",
"supported_adapters": ["nonebot.adapters.onebot.v11"],
"valid": True,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"version": "1.0.0",
"skip_test": False,
},
Expand Down Expand Up @@ -295,7 +295,7 @@ async def test_process_pull_request_skip_plugin_test(
"type": "application",
"supported_adapters": ["nonebot.adapters.onebot.v11"],
"valid": True,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"version": "0.0.1",
"skip_test": True,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/github/publish/utils/test_trigger_registry_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def test_trigger_registry_update(
"type": "application",
"supported_adapters": ["nonebot.adapters.onebot.v11"],
"valid": True,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"version": "1.0.0",
"skip_test": False,
},
Expand Down Expand Up @@ -176,7 +176,7 @@ async def test_trigger_registry_update_skip_test(
"type": "application",
"supported_adapters": ["nonebot.adapters.onebot.v11"],
"valid": True,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"version": "0.0.1",
"skip_test": True,
},
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/store_test/test_validate_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def test_validate_plugin(mocked_api: MockRouter, mocker: MockerFixture) ->
skip_test=False,
supported_adapters=None,
tags=[],
time="2023-09-01T00:00:00+00:00Z",
time="2023-09-01T00:00:00+00:00",
type="application",
valid=True,
version="0.2.0",
Expand Down Expand Up @@ -184,7 +184,7 @@ async def test_validate_plugin_with_previous(
"type": "application",
"supported_adapters": None,
"valid": True,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"version": "0.2.0",
"skip_test": False,
}
Expand Down Expand Up @@ -260,7 +260,7 @@ async def test_validate_plugin_skip_test(
skip_test=False,
supported_adapters=None,
tags=[],
time="2023-09-01T00:00:00+00:00Z",
time="2023-09-01T00:00:00+00:00",
type="application",
valid=True,
version="0.2.0",
Expand Down Expand Up @@ -410,7 +410,7 @@ async def test_validate_plugin_failed_with_previous(
"data": {
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "he0119",
Expand Down Expand Up @@ -467,7 +467,7 @@ async def test_validate_plugin_failed_with_previous(
skip_test=False,
supported_adapters=None,
tags=[],
time="2023-09-01T00:00:00+00:00Z",
time="2023-09-01T00:00:00+00:00",
type="application",
valid=False,
version="0.3.9",
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/validation/fields/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def test_fields_missing_plugin(mocked_api: MockRouter) -> None:
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"author": "author",
"author_id": 1,
"tags": [{"label": "test", "color": "#ffffff"}],
Expand Down Expand Up @@ -58,7 +58,7 @@ async def test_fields_missing_plugin(mocked_api: MockRouter) -> None:
"load": False,
"test_output": "error",
"version": None,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
},
},
{
Expand All @@ -77,7 +77,7 @@ async def test_fields_missing_plugin(mocked_api: MockRouter) -> None:
"load": False,
"test_output": "error",
"version": None,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
},
},
{
Expand All @@ -96,7 +96,7 @@ async def test_fields_missing_plugin(mocked_api: MockRouter) -> None:
"load": False,
"test_output": "error",
"version": None,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
},
},
{
Expand All @@ -115,7 +115,7 @@ async def test_fields_missing_plugin(mocked_api: MockRouter) -> None:
"load": False,
"test_output": "error",
"version": None,
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/validation/fields/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def test_name_too_long(mocked_api: MockRouter) -> None:
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"desc": "desc",
"author": "author",
"homepage": "https://nonebot.dev",
Expand Down
10 changes: 5 additions & 5 deletions tests/utils/validation/fields/test_plugin_supported_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ async def test_plugin_supported_adapters_none(mocked_api: MockRouter) -> None:
"load": True,
"version": "0.0.1",
"test_output": "test_output",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
}
)
assert result.valid_data == snapshot(
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down Expand Up @@ -75,7 +75,7 @@ async def test_plugin_supported_adapters_set(mocked_api: MockRouter) -> None:
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down Expand Up @@ -119,7 +119,7 @@ async def test_plugin_supported_adapters_json(mocked_api: MockRouter) -> None:
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down Expand Up @@ -167,7 +167,7 @@ async def test_plugin_supported_adapters_missing_adapters(
{
"module_name": "module_name",
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/validation/fields/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_project_link_invalid(mocked_api: MockRouter) -> None:
assert result.valid_data == snapshot(
{
"module_name": "module_name",
"time": "2023-10-01T00:00:00+00:00Z",
"time": "2023-10-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down Expand Up @@ -54,7 +54,7 @@ async def test_module_name_invalid(mocked_api: MockRouter) -> None:
assert result.valid_data == snapshot(
{
"project_link": "project_link",
"time": "2023-09-01T00:00:00+00:00Z",
"time": "2023-09-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down Expand Up @@ -183,7 +183,7 @@ async def test_project_link_normalization(mocked_api: MockRouter) -> None:
{
"module_name": "module_name",
"project_link": "project-link-normalization",
"time": "2023-10-01T00:00:00+00:00Z",
"time": "2023-10-01T00:00:00+00:00",
"name": "name",
"desc": "desc",
"author": "author",
Expand Down
Loading
Loading