Skip to content

Commit 77267a1

Browse files
authored
feat: 插件测试结果显示版本号和发布时间 (#303)
* feat: 插件插件测试结果显示版本号和发布时间 * fix: 格式化时间
1 parent 20b9048 commit 77267a1

File tree

18 files changed

+72
-51
lines changed

18 files changed

+72
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- 插件插件测试结果显示版本号和发布时间
13+
1014
### Fixed
1115

1216
- 修复 Docker Test 报错后仍无法运行的问题

src/plugins/github/plugins/publish/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@
5959
"supported_adapters": "插件支持的适配器",
6060
"metadata": "插件测试元数据",
6161
"load": "插件是否成功加载",
62+
"version": "插件版本号",
63+
"time": "插件发布时间",
6264
}

src/plugins/github/plugins/publish/render.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from pathlib import Path
23
from typing import Any
34

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

3839

40+
def key_to_name(key: str) -> str:
41+
"""将 key 转换为可读名称"""
42+
return _loc_to_name(key)
43+
44+
45+
def format_time(time: str) -> str:
46+
"""格式化时间"""
47+
dt = datetime.fromisoformat(time)
48+
return dt.strftime("%Y-%m-%d %H:%M:%S")
49+
50+
3951
env = jinja2.Environment(
4052
loader=jinja2.FileSystemLoader(Path(__file__).parent / "templates"),
4153
enable_async=True,
@@ -48,6 +60,8 @@ def loc_to_name(loc: list[str | int]) -> str:
4860
env.filters["tags_to_str"] = tags_to_str
4961
env.filters["supported_adapters_to_str"] = supported_adapters_to_str
5062
env.filters["loc_to_name"] = loc_to_name
63+
env.filters["key_to_name"] = key_to_name
64+
env.filters["format_time"] = format_time
5165

5266

5367
async def render_comment(result: ValidationDict, reuse: bool = False) -> str:
@@ -64,6 +78,8 @@ async def render_comment(result: ValidationDict, reuse: bool = False) -> str:
6478
"project_link",
6579
"type",
6680
"supported_adapters",
81+
"time",
82+
"version",
6783
]
6884

6985
for key in data.copy():

src/plugins/github/plugins/publish/templates/render_data.md.jinja

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
{%- else %}
1616
插件 <a href="{{ value }}">加载测试</a> 通过。
1717
{%- endif %}
18-
{% else %}
19-
{{ key }}: {{ value }}。
18+
{%- elif key == "time" %}
19+
插件发布时间:{{ value|format_time }}。
20+
{%- else %}
21+
{{ key|key_to_name }}: {{ value }}。
2022
{%- endif %}
2123
{% endmacro %}

src/providers/validation/models.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ class PluginPublishInfo(PublishInfo, PyPIMixin):
210210
skip_test: bool
211211
"""是否跳过插件测试"""
212212
version: str
213-
"""插件版本号
214-
215-
从 PyPI 获取或者测试中获取
216-
"""
213+
"""插件版本号"""
217214
test_config: str = ""
218215
"""插件测试配置"""
219216
test_output: str = ""

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ def mocked_api(respx_mock: MockRouter):
122122
).respond(
123123
json={
124124
"info": {"name": "project_link", "version": "0.0.1"},
125-
"urls": [{"upload_time_iso_8601": "2023-09-01T00:00:00+00:00Z"}],
125+
"urls": [{"upload_time_iso_8601": "2023-09-01T00:00:00+00:00"}],
126126
}
127127
)
128128
respx_mock.get(
129129
"https://pypi.org/pypi/project_link//json", name="project_link/"
130130
).respond(
131131
json={
132132
"info": {"name": "project_link/", "version": "0.0.1"},
133-
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
133+
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
134134
}
135135
)
136136
respx_mock.get(
@@ -161,7 +161,7 @@ def mocked_api(respx_mock: MockRouter):
161161
).respond(
162162
json={
163163
"info": {"name": "project_link1", "version": "0.5.0"},
164-
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
164+
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
165165
}
166166
)
167167
respx_mock.get(
@@ -173,7 +173,7 @@ def mocked_api(respx_mock: MockRouter):
173173
).respond(
174174
json={
175175
"info": {"name": "project-link-normalization", "version": "0.0.1"},
176-
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00Z"}],
176+
"urls": [{"upload_time_iso_8601": "2023-10-01T00:00:00+00:00"}],
177177
}
178178
)
179179
respx_mock.get("https://www.baidu.com", name="homepage_failed").respond(404)

tests/github/config/process/test_config_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def test_process_config_check(
148148
149149
<details>
150150
<summary>详情</summary>
151-
<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>
151+
<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>
152152
</details>
153153
154154
---

tests/github/publish/process/test_publish_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async def test_adapter_process_publish_check(
320320
321321
<details>
322322
<summary>详情</summary>
323-
<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>
323+
<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>
324324
</details>
325325
326326
---
@@ -1228,7 +1228,7 @@ async def test_skip_plugin_check(
12281228
12291229
<details>
12301230
<summary>详情</summary>
1231-
<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>
1231+
<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>
12321232
</details>
12331233
12341234
---

tests/github/publish/process/test_publish_pull_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def test_process_pull_request(
9898
"type": "application",
9999
"supported_adapters": ["nonebot.adapters.onebot.v11"],
100100
"valid": True,
101-
"time": "2023-09-01T00:00:00+00:00Z",
101+
"time": "2023-09-01T00:00:00+00:00",
102102
"version": "1.0.0",
103103
"skip_test": False,
104104
},
@@ -295,7 +295,7 @@ async def test_process_pull_request_skip_plugin_test(
295295
"type": "application",
296296
"supported_adapters": ["nonebot.adapters.onebot.v11"],
297297
"valid": True,
298-
"time": "2023-09-01T00:00:00+00:00Z",
298+
"time": "2023-09-01T00:00:00+00:00",
299299
"version": "0.0.1",
300300
"skip_test": True,
301301
},

tests/github/publish/utils/test_trigger_registry_update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def test_trigger_registry_update(
7878
"type": "application",
7979
"supported_adapters": ["nonebot.adapters.onebot.v11"],
8080
"valid": True,
81-
"time": "2023-09-01T00:00:00+00:00Z",
81+
"time": "2023-09-01T00:00:00+00:00",
8282
"version": "1.0.0",
8383
"skip_test": False,
8484
},
@@ -176,7 +176,7 @@ async def test_trigger_registry_update_skip_test(
176176
"type": "application",
177177
"supported_adapters": ["nonebot.adapters.onebot.v11"],
178178
"valid": True,
179-
"time": "2023-09-01T00:00:00+00:00Z",
179+
"time": "2023-09-01T00:00:00+00:00",
180180
"version": "0.0.1",
181181
"skip_test": True,
182182
},

0 commit comments

Comments
 (0)