diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1051d3aa..4d72ec03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
## [Unreleased]
+### Changed
+
+- 发布检查时第一时间评论议题并修改标题
+
### Fixed
- 修复合并插件配置后没有删除对应分支和关闭议题的问题
diff --git a/src/plugins/github/plugins/publish/__init__.py b/src/plugins/github/plugins/publish/__init__.py
index 9f7a7844..07e04f89 100644
--- a/src/plugins/github/plugins/publish/__init__.py
+++ b/src/plugins/github/plugins/publish/__init__.py
@@ -162,23 +162,23 @@ async def handle_pull_request_and_update_issue(
installation_id: int = Depends(get_installation_id),
) -> None:
async with bot.as_installation(installation_id):
- branch_name = f"{BRANCH_NAME_PREFIX}{handler.issue_number}"
+ # 渲染评论信息
+ comment = await render_comment(validation, True)
+
+ # 对议题评论
+ await handler.comment_issue(comment)
# 设置拉取请求与议题的标题
# 限制标题长度,过长的标题不好看
title = f"{validation.type}: {validation.name[:TITLE_MAX_LENGTH]}"
- # 渲染评论信息
- comment = await render_comment(validation, True)
-
- # 验证之后创建拉取请求和修改议题的标题
- await process_pull_request(handler, validation, branch_name, title)
-
# 修改议题标题
await handler.update_issue_title(title)
- # 对议题评论
- await handler.comment_issue(comment)
+ branch_name = f"{BRANCH_NAME_PREFIX}{handler.issue_number}"
+
+ # 验证之后创建拉取请求和修改议题的标题
+ await process_pull_request(handler, validation, branch_name, title)
async def pr_close_rule(
diff --git a/tests/github/publish/process/test_publish_check.py b/tests/github/publish/process/test_publish_check.py
index 2c179e31..78fa5c0d 100644
--- a/tests/github/publish/process/test_publish_check.py
+++ b/tests/github/publish/process/test_publish_check.py
@@ -74,28 +74,6 @@ async def test_bot_process_publish_check(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
- ctx.should_call_api(
- "rest.pulls.async_create",
- {
- "owner": "he0119",
- "repo": "action-test",
- "title": "Bot: test",
- "body": "resolve #80",
- "base": "master",
- "head": "publish/issue80",
- },
- mock_pulls_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_add_labels",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 2,
- "labels": ["Bot"],
- },
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -135,6 +113,28 @@ async def test_bot_process_publish_check(
},
True,
)
+ ctx.should_call_api(
+ "rest.pulls.async_create",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "title": "Bot: test",
+ "body": "resolve #80",
+ "base": "master",
+ "head": "publish/issue80",
+ },
+ mock_pulls_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_add_labels",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 2,
+ "labels": ["Bot"],
+ },
+ True,
+ )
ctx.receive_event(bot, event)
@@ -264,40 +264,6 @@ async def test_adapter_process_publish_check(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
- ctx.should_call_api(
- "rest.pulls.async_create",
- {
- "owner": "he0119",
- "repo": "action-test",
- "title": snapshot("Adapter: test"),
- "body": "resolve #80",
- "base": "master",
- "head": "publish/issue80",
- },
- mock_pulls_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_add_labels",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 2,
- "labels": ["Adapter"],
- },
- True,
- )
- ctx.should_call_api(
- "rest.issues.async_update",
- snapshot(
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 80,
- "title": "Adapter: test",
- }
- ),
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -337,6 +303,40 @@ async def test_adapter_process_publish_check(
},
True,
)
+ ctx.should_call_api(
+ "rest.issues.async_update",
+ snapshot(
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 80,
+ "title": "Adapter: test",
+ }
+ ),
+ True,
+ )
+ ctx.should_call_api(
+ "rest.pulls.async_create",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "title": snapshot("Adapter: test"),
+ "body": "resolve #80",
+ "base": "master",
+ "head": "publish/issue80",
+ },
+ mock_pulls_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_add_labels",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 2,
+ "labels": ["Adapter"],
+ },
+ True,
+ )
ctx.receive_event(bot, event)
@@ -556,40 +556,6 @@ async def test_plugin_process_publish_check(
),
True,
)
- ctx.should_call_api(
- "rest.pulls.async_create",
- {
- "owner": "he0119",
- "repo": "action-test",
- "title": snapshot("Plugin: name"),
- "body": "resolve #80",
- "base": "master",
- "head": "publish/issue80",
- },
- mock_pulls_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_add_labels",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 2,
- "labels": ["Plugin"],
- },
- True,
- )
- ctx.should_call_api(
- "rest.issues.async_update",
- snapshot(
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 80,
- "title": "Plugin: name",
- }
- ),
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -629,6 +595,40 @@ async def test_plugin_process_publish_check(
},
True,
)
+ ctx.should_call_api(
+ "rest.issues.async_update",
+ snapshot(
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 80,
+ "title": "Plugin: name",
+ }
+ ),
+ True,
+ )
+ ctx.should_call_api(
+ "rest.pulls.async_create",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "title": snapshot("Plugin: name"),
+ "body": "resolve #80",
+ "base": "master",
+ "head": "publish/issue80",
+ },
+ mock_pulls_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_add_labels",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 2,
+ "labels": ["Plugin"],
+ },
+ True,
+ )
ctx.receive_event(bot, event)
@@ -853,40 +853,6 @@ async def test_plugin_process_publish_check_re_run(
),
True,
)
- ctx.should_call_api(
- "rest.pulls.async_create",
- {
- "owner": "he0119",
- "repo": "action-test",
- "title": snapshot("Plugin: name"),
- "body": "resolve #80",
- "base": "master",
- "head": "publish/issue80",
- },
- mock_pulls_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_add_labels",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 2,
- "labels": ["Plugin"],
- },
- True,
- )
- ctx.should_call_api(
- "rest.issues.async_update",
- snapshot(
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 80,
- "title": "Plugin: name",
- }
- ),
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -926,6 +892,40 @@ async def test_plugin_process_publish_check_re_run(
},
True,
)
+ ctx.should_call_api(
+ "rest.issues.async_update",
+ snapshot(
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 80,
+ "title": "Plugin: name",
+ }
+ ),
+ True,
+ )
+ ctx.should_call_api(
+ "rest.pulls.async_create",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "title": snapshot("Plugin: name"),
+ "body": "resolve #80",
+ "base": "master",
+ "head": "publish/issue80",
+ },
+ mock_pulls_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_add_labels",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 2,
+ "labels": ["Plugin"],
+ },
+ True,
+ )
ctx.receive_event(bot, event)
@@ -1064,89 +1064,89 @@ async def test_edit_title(
mock_issues_resp,
)
ctx.should_call_api(
- "rest.pulls.async_create",
+ "rest.issues.async_list_comments",
+ {"owner": "he0119", "repo": "action-test", "issue_number": 80},
+ mock_list_comments_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_create_comment",
{
"owner": "he0119",
"repo": "action-test",
- "title": "Bot: test1",
- "body": "resolve #80",
- "base": "master",
- "head": "publish/issue80",
+ "issue_number": 80,
+ "body": snapshot(
+ """\
+# 📃 商店发布检查结果
+
+> Bot: test1
+
+**✅ 所有测试通过,一切准备就绪!**
+
+
+
+详情
+✅ 项目 主页 返回状态码 200。✅ 标签: test-#ffffff。
+
+
+---
+
+💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
+💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试。
+
+♻️ 评论已更新至最新检查结果
+
+💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
+
+"""
+ ),
},
- exception=RequestFailed(
- Response(
- httpx.Response(422, request=httpx.Request("test", "test")),
- None, # type: ignore
- )
- ),
+ True,
)
+ # 修改议题标题
ctx.should_call_api(
- "rest.pulls.async_list",
+ "rest.issues.async_update",
{
"owner": "he0119",
"repo": "action-test",
- "head": "he0119:publish/issue80",
+ "issue_number": 80,
+ "title": "Bot: test1",
},
- mock_pulls_resp,
+ True,
)
- # 修改标题
ctx.should_call_api(
- "rest.pulls.async_update",
+ "rest.pulls.async_create",
{
"owner": "he0119",
"repo": "action-test",
- "pull_number": 2,
"title": "Bot: test1",
+ "body": "resolve #80",
+ "base": "master",
+ "head": "publish/issue80",
},
- True,
+ exception=RequestFailed(
+ Response(
+ httpx.Response(422, request=httpx.Request("test", "test")),
+ None, # type: ignore
+ )
+ ),
)
ctx.should_call_api(
- "rest.issues.async_update",
+ "rest.pulls.async_list",
{
"owner": "he0119",
"repo": "action-test",
- "issue_number": 80,
- "title": "Bot: test1",
+ "head": "he0119:publish/issue80",
},
- True,
- )
-
- ctx.should_call_api(
- "rest.issues.async_list_comments",
- {"owner": "he0119", "repo": "action-test", "issue_number": 80},
- mock_list_comments_resp,
+ mock_pulls_resp,
)
+ # 修改拉取请求标题
ctx.should_call_api(
- "rest.issues.async_create_comment",
+ "rest.pulls.async_update",
{
"owner": "he0119",
"repo": "action-test",
- "issue_number": 80,
- "body": snapshot(
- """\
-# 📃 商店发布检查结果
-
-> Bot: test1
-
-**✅ 所有测试通过,一切准备就绪!**
-
-
-
-详情
-✅ 项目 主页 返回状态码 200。✅ 标签: test-#ffffff。
-
-
----
-
-💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
-💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试。
-
-♻️ 评论已更新至最新检查结果
-
-💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
-
-"""
- ),
+ "pull_number": 2,
+ "title": "Bot: test1",
},
True,
)
@@ -1281,26 +1281,6 @@ async def test_edit_title_too_long(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
- ctx.should_call_api(
- "rest.pulls.async_list",
- {
- "owner": "he0119",
- "repo": "action-test",
- "head": "he0119:publish/issue80",
- },
- mock_pulls_resp,
- )
- # 修改标题,应该被截断,且不会更新拉取请求的标题
- ctx.should_call_api(
- "rest.issues.async_update",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 80,
- "title": "Bot: looooooooooooooooooooooooooooooooooooooooooooooooo",
- },
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
@@ -1341,6 +1321,26 @@ async def test_edit_title_too_long(
},
True,
)
+ # 修改标题,应该被截断,且不会更新拉取请求的标题
+ ctx.should_call_api(
+ "rest.issues.async_update",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 80,
+ "title": "Bot: looooooooooooooooooooooooooooooooooooooooooooooooo",
+ },
+ True,
+ )
+ ctx.should_call_api(
+ "rest.pulls.async_list",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "head": "he0119:publish/issue80",
+ },
+ mock_pulls_resp,
+ )
ctx.receive_event(bot, event)
@@ -1409,15 +1409,6 @@ async def test_process_publish_check_not_pass(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
- ctx.should_call_api(
- "rest.pulls.async_list",
- {
- "owner": "he0119",
- "repo": "action-test",
- "head": "he0119:publish/issue80",
- },
- mock_pulls_resp,
- )
# 检查是否可以复用评论
ctx.should_call_api(
"rest.issues.async_list_comments",
@@ -1460,6 +1451,15 @@ async def test_process_publish_check_not_pass(
},
True,
)
+ ctx.should_call_api(
+ "rest.pulls.async_list",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "head": "he0119:publish/issue80",
+ },
+ mock_pulls_resp,
+ )
ctx.receive_event(bot, event)
@@ -1728,7 +1728,6 @@ async def test_skip_plugin_check(
),
True,
)
-
ctx.should_call_api(
"rest.issues.async_update",
{
@@ -1773,27 +1772,6 @@ async def test_skip_plugin_check(
},
True,
)
- ctx.should_call_api(
- "rest.pulls.async_list",
- {
- "owner": "he0119",
- "repo": "action-test",
- "head": "he0119:publish/issue70",
- },
- mock_pulls_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_update",
- snapshot(
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 70,
- "title": "Plugin: project_link",
- }
- ),
- True,
- )
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 70},
@@ -1834,6 +1812,27 @@ async def test_skip_plugin_check(
},
True,
)
+ ctx.should_call_api(
+ "rest.issues.async_update",
+ snapshot(
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 70,
+ "title": "Plugin: project_link",
+ }
+ ),
+ True,
+ )
+ ctx.should_call_api(
+ "rest.pulls.async_list",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "head": "he0119:publish/issue70",
+ },
+ mock_pulls_resp,
+ )
ctx.receive_event(bot, event)
@@ -1913,31 +1912,12 @@ async def test_convert_pull_request_to_draft(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
- ctx.should_call_api(
- "rest.pulls.async_list",
- {
- "owner": "he0119",
- "repo": "action-test",
- "head": "he0119:publish/issue80",
- },
- mock_pulls_resp,
- )
- # 将拉取请求转换为草稿
- ctx.should_call_api(
- "async_graphql",
- {
- "query": "mutation convertPullRequestToDraft($pullRequestId: ID!) {\n convertPullRequestToDraft(input: {pullRequestId: $pullRequestId}) {\n clientMutationId\n }\n }",
- "variables": {"pullRequestId": "123"},
- },
- True,
- )
# 检查是否可以复用评论
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_list_comments_resp,
)
-
ctx.should_call_api(
"rest.issues.async_create_comment",
{
@@ -1973,6 +1953,24 @@ async def test_convert_pull_request_to_draft(
},
True,
)
+ ctx.should_call_api(
+ "rest.pulls.async_list",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "head": "he0119:publish/issue80",
+ },
+ mock_pulls_resp,
+ )
+ # 将拉取请求转换为草稿
+ ctx.should_call_api(
+ "async_graphql",
+ {
+ "query": "mutation convertPullRequestToDraft($pullRequestId: ID!) {\n convertPullRequestToDraft(input: {pullRequestId: $pullRequestId}) {\n clientMutationId\n }\n }",
+ "variables": {"pullRequestId": "123"},
+ },
+ True,
+ )
ctx.receive_event(bot, event)
@@ -2054,7 +2052,45 @@ async def test_process_publish_check_ready_for_review(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
+ ctx.should_call_api(
+ "rest.issues.async_list_comments",
+ {"owner": "he0119", "repo": "action-test", "issue_number": 80},
+ mock_list_comments_resp,
+ )
+ ctx.should_call_api(
+ "rest.issues.async_create_comment",
+ {
+ "owner": "he0119",
+ "repo": "action-test",
+ "issue_number": 80,
+ "body": snapshot(
+ """\
+# 📃 商店发布检查结果
+
+> Bot: test
+
+**✅ 所有测试通过,一切准备就绪!**
+
+
+
+详情
+✅ 项目 主页 返回状态码 200。✅ 标签: test-#ffffff。
+
+
+---
+
+💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
+💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试。
+♻️ 评论已更新至最新检查结果
+
+💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
+
+"""
+ ),
+ },
+ True,
+ )
ctx.should_call_api(
"rest.pulls.async_create",
{
@@ -2098,45 +2134,6 @@ async def test_process_publish_check_ready_for_review(
},
True,
)
- ctx.should_call_api(
- "rest.issues.async_list_comments",
- {"owner": "he0119", "repo": "action-test", "issue_number": 80},
- mock_list_comments_resp,
- )
- ctx.should_call_api(
- "rest.issues.async_create_comment",
- {
- "owner": "he0119",
- "repo": "action-test",
- "issue_number": 80,
- "body": snapshot(
- """\
-# 📃 商店发布检查结果
-
-> Bot: test
-
-**✅ 所有测试通过,一切准备就绪!**
-
-
-
-详情
-✅ 项目 主页 返回状态码 200。✅ 标签: test-#ffffff。
-
-
----
-
-💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。
-💡 当插件加载测试失败时,请发布新版本后勾选插件测试勾选框重新运行插件测试。
-
-♻️ 评论已更新至最新检查结果
-
-💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)
-
-"""
- ),
- },
- True,
- )
ctx.receive_event(bot, event)