Skip to content

Commit

Permalink
feat: 新增插件重测按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOrangeQWQ committed Sep 2, 2024
1 parent 39d6f46 commit 9ea1728
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
commit_and_push,
create_pull_request,
ensure_issue_content,
ensure_issue_test_button,
resolve_conflict_pull_requests,
run_shell_command,
should_skip_plugin_publish,
should_skip_plugin_test,
trigger_registry_update,
update_file,
Expand Down Expand Up @@ -177,6 +179,8 @@ async def handle_publish_plugin_check(
if issue.state != "open":
logger.info("议题未开启,已跳过")
await publish_check_matcher.finish()
if should_skip_plugin_publish(issue):
logger.info("测试按钮已勾选,跳过插件发布检查")

# 是否需要跳过插件测试
plugin_config.skip_plugin_test = await should_skip_plugin_test(
Expand Down Expand Up @@ -235,7 +239,7 @@ async def handle_publish_plugin_check(
**repo_info.model_dump(), issue_number=issue_number, title=title
)
logger.info(f"议题标题已修改为 {title}")

await ensure_issue_test_button(bot, repo_info, issue_number, issue.body or "")
await comment_issue(bot, repo_info, issue_number, result)


Expand Down
3 changes: 3 additions & 0 deletions src/plugins/publish/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
PLUGIN_TYPE_STRING = "插件类型"
PLUGIN_TYPE_PATTERN = re.compile(ISSUE_PATTERN.format(PLUGIN_TYPE_STRING))
PLUGIN_CONFIG_PATTERN = re.compile(r"### 插件配置项\s+```(?:\w+)?\s?([\s\S]*?)```")
PLUGIN_TEST_STRING = "插件测试"
PLUGIN_TEST_BUTTON_STRING = "- [x] 单击左侧按钮重新测试,完成时勾选框将被选中"
PLUGIN_TEST_BUTTON_PATTERN = re.compile(r"- \[(.)\] 单击左侧按钮重新测试")
PLUGIN_SUPPORTED_ADAPTERS_STRING = "插件支持的适配器"
PLUGIN_SUPPORTED_ADAPTERS_PATTERN = re.compile(
ISSUE_PATTERN.format(PLUGIN_SUPPORTED_ADAPTERS_STRING)
Expand Down
1 change: 0 additions & 1 deletion src/plugins/publish/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jinja2

from src.utils.validation.models import PublishType
from src.utils.store_test.models import Tag

from .config import plugin_config
from .constants import LOC_NAME_MAP
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/publish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
PLUGIN_NAME_PATTERN,
PLUGIN_STRING_LIST,
PLUGIN_SUPPORTED_ADAPTERS_PATTERN,
PLUGIN_TEST_BUTTON_STRING,
PLUGIN_TEST_BUTTON_PATTERN,
PLUGIN_TEST_STRING,
PLUGIN_TYPE_PATTERN,
PROJECT_LINK_PATTERN,
SKIP_PLUGIN_TEST_COMMENT,
Expand Down Expand Up @@ -539,6 +542,32 @@ async def ensure_issue_content(
logger.info("检测到议题内容缺失,已更新")


async def ensure_issue_test_button(
bot: Bot, repo_info: RepoInfo, issue_number: int, issue_body: str
):
"""确保议题内容中包含插件重测按钮"""
search_result = PLUGIN_TEST_BUTTON_PATTERN.search(issue_body)
if not search_result:
new_content = f"{PLUGIN_TEST_STRING}\n\n{PLUGIN_TEST_BUTTON_STRING}"
await bot.rest.issues.async_update(
**repo_info.model_dump(),
issue_number=issue_number,
body=f"{issue_body}\n\n{new_content}",
)
logger.info("为议题添加插件测试按钮。")


async def should_skip_plugin_publish(
issue: "Issue",
) -> bool:
"""判断是否跳过插件测试"""
body = issue.body if issue.body else ""
search_result = PLUGIN_TEST_BUTTON_PATTERN.search(body)
if search_result:
return search_result.group(1) == "x"
return False


async def trigger_registry_update(
bot: GitHubBot, repo_info: RepoInfo, publish_type: PublishType, issue: "Issue"
):
Expand Down

0 comments on commit 9ea1728

Please sign in to comment.