Skip to content

Commit

Permalink
fix: 修复修改议题后无法重新测试的问题 (#244)
Browse files Browse the repository at this point in the history
同时默认不勾选测试按钮,在勾选时再重新测试
  • Loading branch information
he0119 authored Oct 31, 2024
1 parent b976939 commit 499dfff
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 140 deletions.
8 changes: 2 additions & 6 deletions src/plugins/github/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
from .depends import get_type_by_labels
from .utils import (
ensure_issue_content,
ensure_issue_test_button,
is_plugin_test_button_check,
ensure_issue_plugin_test_button,
process_pull_request,
resolve_conflict_pull_requests,
trigger_registry_update,
Expand Down Expand Up @@ -155,9 +154,6 @@ async def handle_publish_plugin_check(
if issue.state != "open":
logger.info("议题未开启,已跳过")
await publish_check_matcher.finish()
if is_plugin_test_button_check(issue):
logger.info("测试按钮已勾选,跳过插件发布检查")
await publish_check_matcher.finish()

# 是否需要跳过插件测试
skip_test = await handler.should_skip_test()
Expand All @@ -170,7 +166,7 @@ async def handle_publish_plugin_check(
result = await validate_plugin_info_from_issue(issue, handler, skip_test)

# 确保插件重测按钮存在
await ensure_issue_test_button(handler)
await ensure_issue_plugin_test_button(handler)

state["handler"] = handler
state["validation"] = result
Expand Down
7 changes: 3 additions & 4 deletions src/plugins/github/plugins/publish/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
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"- \[([ |x])\] 单击左侧按钮重新测试,完成时勾选框将被选中"
)
PLUGIN_TEST_BUTTON_TIPS = "如需重新运行插件测试,请勾选左侧勾选框"
PLUGIN_TEST_BUTTON_STRING = f"- [ ] {PLUGIN_TEST_BUTTON_TIPS}"
PLUGIN_TEST_BUTTON_PATTERN = re.compile(rf"- \[([ |x])\] {PLUGIN_TEST_BUTTON_TIPS}")
PLUGIN_SUPPORTED_ADAPTERS_STRING = "插件支持的适配器"
PLUGIN_SUPPORTED_ADAPTERS_PATTERN = re.compile(
ISSUE_PATTERN.format(PLUGIN_SUPPORTED_ADAPTERS_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
---

💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试

{% if reuse %}
♻️ 评论已更新至最新检查结果
Expand Down
16 changes: 3 additions & 13 deletions src/plugins/github/plugins/publish/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

if TYPE_CHECKING:
from githubkit.rest import (
Issue,
PullRequest,
PullRequestSimple,
PullRequestSimplePropLabelsItems,
Expand Down Expand Up @@ -178,15 +177,6 @@ def update_file(result: ValidationDict) -> None:
logger.info("文件更新完成")


def is_plugin_test_button_check(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 ensure_issue_content(handler: IssueHandler):
"""确保议题内容中包含所需的插件信息"""
new_content = []
Expand All @@ -203,7 +193,7 @@ async def ensure_issue_content(handler: IssueHandler):
logger.info("检测到议题内容缺失,已更新")


async def ensure_issue_test_button(handler: IssueHandler):
async def ensure_issue_plugin_test_button(handler: IssueHandler):
"""确保议题内容中包含插件重测按钮"""
issue_body = handler.issue.body or ""

Expand All @@ -213,12 +203,12 @@ async def ensure_issue_test_button(handler: IssueHandler):

await handler.update_issue_content(f"{issue_body}\n\n{new_content}")
logger.info("为议题添加插件重测按钮")
elif search_result.group(1) == " ":
elif search_result.group(1) == "x":
new_content = issue_body.replace(
search_result.group(0), PLUGIN_TEST_BUTTON_STRING
)
await handler.update_issue_content(f"{new_content}")
logger.info("选中议题的插件测试按钮")
logger.info("取消勾选议题的插件测试按钮")


async def process_pull_request(
Expand Down
101 changes: 9 additions & 92 deletions tests/github/publish/process/test_publish_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
MockIssue,
check_json_data,
generate_issue_body_bot,
generate_issue_body_plugin_test_button,
get_github_bot,
get_issue_labels,
)
Expand Down Expand Up @@ -127,7 +126,7 @@ async def test_bot_process_publish_check(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -333,7 +332,7 @@ async def test_adapter_process_publish_check(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -559,7 +558,7 @@ async def test_edit_title(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -754,7 +753,7 @@ async def test_edit_title_too_long(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -876,7 +875,7 @@ async def test_process_publish_check_not_pass(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -1149,7 +1148,7 @@ async def test_skip_plugin_check(
### 插件测试
- [x] 单击左侧按钮重新测试,完成时勾选框将被选中\
- [ ] 如需重新运行插件测试,请勾选左侧勾选框\
"""
),
},
Expand Down Expand Up @@ -1205,7 +1204,7 @@ async def test_skip_plugin_check(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -1241,88 +1240,6 @@ async def test_skip_plugin_check(
assert mocked_api["project_link"].called


async def test_button_skip_publish_check(
app: App,
mocker: MockerFixture,
mocked_api: MockRouter,
tmp_path: Path,
mock_installation,
) -> None:
"""重测按钮被选中,跳过发布流程"""
from src.plugins.github import plugin_config
from src.plugins.github.plugins.publish import publish_check_matcher

mock_subprocess_run = mocker.patch(
"subprocess.run", side_effect=lambda *args, **kwargs: mocker.MagicMock()
)

mock_issue = MockIssue(
body=generate_issue_body_plugin_test_button(
body=MockBody(type="plugin").generate(), selected=True
)
).as_mock(mocker)

mock_event = mocker.MagicMock()
mock_event.issue = mock_issue

mock_issues_resp = mocker.MagicMock()
mock_issues_resp.parsed_data = mock_issue

mock_comment = mocker.MagicMock()
mock_comment.body = "OMG"
mock_comment.author_association = "OWNER"
mock_list_comments_resp = mocker.MagicMock()
mock_list_comments_resp.parsed_data = [mock_comment]

mock_pulls_resp = mocker.MagicMock()
mock_pulls_resp.parsed_data = []

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

check_json_data(plugin_config.input_config.plugin_path, [])

async with app.test_matcher(publish_check_matcher) as ctx:
adapter, bot = get_github_bot(ctx)
event_path = (
Path(__file__).parent.parent.parent / "events" / "issue-comment-skip.json"
)
event = Adapter.payload_to_event("1", "issue_comment", event_path.read_bytes())
assert isinstance(event, IssueCommentCreated)

ctx.should_call_api(
"rest.apps.async_get_repo_installation",
{"owner": "he0119", "repo": "action-test"},
mock_installation,
)
ctx.should_call_api(
"rest.issues.async_get",
{"owner": "he0119", "repo": "action-test", "issue_number": 70},
mock_issues_resp,
)

ctx.receive_event(bot, event)

# 测试 git 命令
mock_subprocess_run.assert_has_calls(
[
mocker.call(
["git", "config", "--global", "safe.directory", "*"],
check=True,
capture_output=True,
),
mocker.call(
["pre-commit", "install", "--install-hooks"],
check=True,
capture_output=True,
),
] # type: ignore
)

# 检查文件是否正确
check_json_data(plugin_config.input_config.plugin_path, [])


async def test_convert_pull_request_to_draft(
app: App,
mocker: MockerFixture,
Expand Down Expand Up @@ -1429,7 +1346,7 @@ async def test_convert_pull_request_to_draft(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down Expand Up @@ -1596,7 +1513,7 @@ async def test_process_publish_check_ready_for_review(
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down
4 changes: 2 additions & 2 deletions tests/github/publish/render/test_publish_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def test_render_empty(app: App):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down Expand Up @@ -59,7 +59,7 @@ async def test_render_reuse(app: App):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
♻️ 评论已更新至最新检查结果
Expand Down
10 changes: 5 additions & 5 deletions tests/github/publish/render/test_publish_render_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def test_render_data_bot(app: App):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_render_data_bot(app: App):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down Expand Up @@ -140,7 +140,7 @@ async def test_render_data_adapter(app: App):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down Expand Up @@ -193,7 +193,7 @@ async def test_render_data_plugin(app: App, mocker: MockFixture):
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down Expand Up @@ -238,7 +238,7 @@ async def test_render_data_plugin_supported_adapters(app: App, mocker: MockFixtu
---
💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试
💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试
💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
Expand Down
Loading

0 comments on commit 499dfff

Please sign in to comment.