diff --git a/src/plugins/github/plugins/publish/constants.py b/src/plugins/github/plugins/publish/constants.py index d6191964..0876688a 100644 --- a/src/plugins/github/plugins/publish/constants.py +++ b/src/plugins/github/plugins/publish/constants.py @@ -6,7 +6,6 @@ BRANCH_NAME_PREFIX = "publish/issue" - # 基本信息 PROJECT_LINK_PATTERN = re.compile(ISSUE_PATTERN.format("PyPI 项目名")) TAGS_PATTERN = re.compile(ISSUE_PATTERN.format("标签")) @@ -47,6 +46,9 @@ ADAPTER_MODULE_NAME_PATTERN = re.compile(ISSUE_PATTERN.format("适配器 import 包名")) ADAPTER_HOMEPAGE_PATTERN = re.compile(ISSUE_PATTERN.format("适配器项目仓库/主页链接")) +# 评论卡片模板 +COMMENT_CARD_TEMPLATE = """[![{name}](https://img.shields.io/badge/{head}-{content}-{color}?style=for-the-badge)]({url})""" + # 发布信息项对应的中文名 LOC_NAME_MAP = { "name": "名称", diff --git a/src/plugins/github/plugins/publish/render.py b/src/plugins/github/plugins/publish/render.py index 03ff6cf7..9abb45a6 100644 --- a/src/plugins/github/plugins/publish/render.py +++ b/src/plugins/github/plugins/publish/render.py @@ -10,7 +10,7 @@ from src.providers.validation import ValidationDict from src.providers.validation.models import PublishType -from .constants import LOC_NAME_MAP +from .constants import COMMENT_CARD_TEMPLATE, LOC_NAME_MAP def tags_to_str(tags: list[dict[str, str]]) -> str: @@ -98,12 +98,31 @@ async def render_comment(result: ValidationDict, reuse: bool = False) -> str: # 按照 display_keys 顺序展示数据 data = {key: valid_data[key] for key in display_keys if key in valid_data} - # homepage 字段单独处理,提供快捷插件审核入口 - homepage: str | None = data.get("homepage") + card: list[str] = [] + if homepage := data.get("homepage"): + card.append( + COMMENT_CARD_TEMPLATE.format( + name="主页", + head="HOMEPAGE", + content="200", + color="green", + url=homepage, + ) + ) + if action_url := data.get("action_url"): + card.append( + COMMENT_CARD_TEMPLATE.format( + name="测试结果", + head="RESULT", + content="OK" if result.valid else "ERROR", + color="green" if result.valid else "red", + url=action_url, + ) + ) template = env.get_template("comment.md.jinja") return await template.render_async( - homepage=homepage, + card=" ".join(card), reuse=reuse, title=title, valid=result.valid, diff --git a/src/plugins/github/plugins/publish/templates/comment.md.jinja b/src/plugins/github/plugins/publish/templates/comment.md.jinja index 43b49be4..a020e943 100644 --- a/src/plugins/github/plugins/publish/templates/comment.md.jinja +++ b/src/plugins/github/plugins/publish/templates/comment.md.jinja @@ -5,8 +5,8 @@ > {{ title }} -{% if homepage %} -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)]({{ homepage }}) +{% if card %} +{{ card }} {% endif -%} diff --git a/tests/plugins/github/config/process/test_config_check.py b/tests/plugins/github/config/process/test_config_check.py index d0d0f57c..c59ba018 100644 --- a/tests/plugins/github/config/process/test_config_check.py +++ b/tests/plugins/github/config/process/test_config_check.py @@ -137,7 +137,7 @@ async def test_process_config_check( > Plugin: name -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) +[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) [![测试结果](https://img.shields.io/badge/RESULT-OK-green?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) **✅ 所有测试通过,一切准备就绪!** diff --git a/tests/plugins/github/publish/process/test_publish_check_plugin.py b/tests/plugins/github/publish/process/test_publish_check_plugin.py index 15383eda..511af134 100644 --- a/tests/plugins/github/publish/process/test_publish_check_plugin.py +++ b/tests/plugins/github/publish/process/test_publish_check_plugin.py @@ -192,7 +192,7 @@ async def test_plugin_process_publish_check( > Plugin: name -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) +[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) [![测试结果](https://img.shields.io/badge/RESULT-OK-green?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) **✅ 所有测试通过,一切准备就绪!** @@ -454,7 +454,7 @@ async def test_plugin_process_publish_check_re_run( > Plugin: name -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) +[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://nonebot.dev) [![测试结果](https://img.shields.io/badge/RESULT-OK-green?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) **✅ 所有测试通过,一切准备就绪!** @@ -700,6 +700,8 @@ async def test_plugin_process_publish_check_missing_metadata( > Plugin: project_link +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 无法获取到插件元数据。
    请确保插件正常加载。
  • @@ -953,6 +955,8 @@ async def test_skip_plugin_check( > Plugin: project_link +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 名称: 无法匹配到数据。
    请确保填写该数据项。
  • ⚠️ 描述: 无法匹配到数据。
    请确保填写该数据项。
  • ⚠️ 项目仓库/主页链接: 无法匹配到数据。
    请确保填写该数据项。
  • ⚠️ 插件类型: 无法匹配到数据。
    请确保填写该数据项。
  • ⚠️ 插件支持的适配器: 无法匹配到数据。
    请确保填写该数据项。
  • ⚠️ 无法获取到插件元数据。
    请确保插件正常加载。
  • diff --git a/tests/plugins/github/publish/render/test_publish_render_data.py b/tests/plugins/github/publish/render/test_publish_render_data.py index 80ce5e73..97e02ec8 100644 --- a/tests/plugins/github/publish/render/test_publish_render_data.py +++ b/tests/plugins/github/publish/render/test_publish_render_data.py @@ -196,7 +196,7 @@ async def test_render_data_plugin(app: App, mocker: MockFixture): > Plugin: 帮助 -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://github.com/he0119/nonebot-plugin-treehelp) +[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://github.com/he0119/nonebot-plugin-treehelp) [![测试结果](https://img.shields.io/badge/RESULT-OK-green?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) **✅ 所有测试通过,一切准备就绪!** @@ -249,6 +249,8 @@ async def test_render_data_plugin_supported_adapters(app: App, mocker: MockFixtu > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-OK-green?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **✅ 所有测试通过,一切准备就绪!** diff --git a/tests/plugins/github/publish/render/test_publish_render_error.py b/tests/plugins/github/publish/render/test_publish_render_error.py index db2fd8c8..6603238e 100644 --- a/tests/plugins/github/publish/render/test_publish_render_error.py +++ b/tests/plugins/github/publish/render/test_publish_render_error.py @@ -231,7 +231,7 @@ async def test_render_error_plugin(app: App, mocker: MockFixture): > Plugin: 帮助 -[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://github.com/he0119/nonebot-plugin-treehelp) +[![主页](https://img.shields.io/badge/HOMEPAGE-200-green?style=for-the-badge)](https://github.com/he0119/nonebot-plugin-treehelp) [![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) **⚠️ 在发布检查过程中,我们发现以下问题:** @@ -359,6 +359,8 @@ async def test_render_error_plugin_metadata(app: App, mocker: MockFixture): > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 插件测试元数据: 无法获取到插件元数据。
  • @@ -427,6 +429,8 @@ async def test_render_error_tags_invalid(app: App, mocker: MockFixture): > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 第 3 个标签格式错误。
    请确保标签为字典。
  • ⚠️ 标签: 格式错误。
    请确保其为列表。
  • ⚠️ 标签: 解码失败。
    请确保其为 JSON 格式。
  • @@ -496,6 +500,8 @@ async def test_render_type_error(app: App, mocker: MockFixture): > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 插件类型 invalid 不符合规范。
    请确保插件类型正确,当前仅支持 application 与 library。
  • ⚠️ 适配器 missing 不存在。
    请确保适配器模块名称正确。
  • ⚠️ 插件支持的适配器: 格式错误。
    请确保其为集合。
  • @@ -552,6 +558,8 @@ async def test_render_unknown_error(app: App, mocker: MockFixture): > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ tests > 2 > test: unknown error
  • @@ -619,6 +627,8 @@ async def test_render_http_error(app: App, mocker: MockFixture): > Plugin: 帮助 +[![测试结果](https://img.shields.io/badge/RESULT-ERROR-red?style=for-the-badge)](https://github.com/owner/repo/actions/runs/123456) + **⚠️ 在发布检查过程中,我们发现以下问题:**
  • ⚠️ 项目 主页 返回状态码 404。
    请确保你的项目主页可访问。
  • ⚠️ 项目 主页 访问出错。
    错误信息