diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33e422f5..a922a83a 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]
+### Added
+
+- 跳过机器人的评论
+
## [2.1.0] - 2023-04-08
### Added
diff --git a/src/plugins/publish/__init__.py b/src/plugins/publish/__init__.py
index 265cfbf5..081fc4f1 100644
--- a/src/plugins/publish/__init__.py
+++ b/src/plugins/publish/__init__.py
@@ -11,7 +11,7 @@
from nonebot.params import Depends
from .config import plugin_config
-from .constants import BRANCH_NAME_PREFIX
+from .constants import BOT_MARKER, BRANCH_NAME_PREFIX
from .depends import (
get_installation_id,
get_issue_number,
@@ -112,6 +112,11 @@ async def handle_pr_close(
async def check_rule(
event: IssuesOpened | IssuesReopened | IssuesEdited | IssueCommentCreated,
) -> bool:
+ if isinstance(
+ event, IssueCommentCreated
+ ) and event.payload.comment.user.login.endswith(BOT_MARKER):
+ logger.info("评论来自机器人,已跳过")
+ return False
if event.payload.issue.pull_request:
logger.info("评论在拉取请求下,已跳过")
return False
diff --git a/src/plugins/publish/constants.py b/src/plugins/publish/constants.py
index e3aad41d..91b0b789 100644
--- a/src/plugins/publish/constants.py
+++ b/src/plugins/publish/constants.py
@@ -2,6 +2,9 @@
NONEFLOW_MARKER = ""
+BOT_MARKER = "[bot]"
+"""机器人的名字结尾都会带有这个"""
+
SKIP_PLUGIN_TEST_COMMENT = "/skip"
COMMENT_TITLE = "# 📃 商店发布检查结果"
diff --git a/tests/publish/plugin-test/issue-comment-bot.json b/tests/publish/plugin-test/issue-comment-bot.json
new file mode 100644
index 00000000..b51b2009
--- /dev/null
+++ b/tests/publish/plugin-test/issue-comment-bot.json
@@ -0,0 +1,252 @@
+{
+ "action": "created",
+ "comment": {
+ "author_association": "NONE",
+ "body": "# 📃 商店发布检查结果\n\n> Plugin: B站直播间路灯\n\n**⚠️ 在发布检查过程中,我们发现以下问题:**\n
⚠️ PyPI 项目名 nonebot-plugin-blive-danmaku 加包名 nonebot_plugin_blive_danmaku 的值与商店重复。请确保没有重复发布。
\n详情
✅ 标签: bilibili-#EA5252。✅ 项目 主页 返回状态码 200。✅ 包 nonebot-plugin-blive-danmaku 已发布至 PyPI。✅ 插件 加载测试 通过。
\n\n---\n\n💡 如需修改信息,请直接修改 issue,机器人会自动更新检查结果。\n💡 当插件加载测试失败时,请发布新版本后在当前页面下评论任意内容以触发测试。\n\n💪 Powered by [NoneFlow](https://github.com/nonebot/noneflow)\n\n",
+ "created_at": "2023-04-10T00:46:24Z",
+ "html_url": "https://github.com/he0119/action-test/issues/101#issuecomment-1501258617",
+ "id": 1501258617,
+ "issue_url": "https://api.github.com/repos/he0119/action-test/issues/101",
+ "node_id": "IC_kwDOEtTRZs5Ze2N5",
+ "performed_via_github_app": null,
+ "reactions": {
+ "+1": 0,
+ "-1": 0,
+ "confused": 0,
+ "eyes": 0,
+ "heart": 0,
+ "hooray": 0,
+ "laugh": 0,
+ "rocket": 0,
+ "total_count": 0,
+ "url": "https://api.github.com/repos/he0119/action-test/issues/comments/1501258617/reactions"
+ },
+ "updated_at": "2023-04-10T00:46:24Z",
+ "url": "https://api.github.com/repos/he0119/action-test/issues/comments/1501258617",
+ "user": {
+ "avatar_url": "https://avatars.githubusercontent.com/u/5219550?v=4",
+ "events_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/events{/privacy}",
+ "followers_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/followers",
+ "following_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/following{/other_user}",
+ "gists_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/apps/noneflow-test",
+ "id": 130064678,
+ "login": "noneflow-test[bot]",
+ "node_id": "BOT_kgDOB8ChJg",
+ "organizations_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/orgs",
+ "received_events_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/received_events",
+ "repos_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/subscriptions",
+ "type": "Bot",
+ "url": "https://api.github.com/users/noneflow-test%5Bbot%5D"
+ }
+ },
+ "issue": {
+ "active_lock_reason": null,
+ "assignee": null,
+ "assignees": [],
+ "author_association": "OWNER",
+ "body": "**插件名称:**\r\n\r\nB站直播间路灯\r\n\r\n**插件功能:**\r\n\r\n通过弹幕记录直播高能点\r\n\r\n**PyPI 项目名:**\r\n\r\nnonebot-plugin-blive-danmaku\r\n\r\n**插件 import 包名:**\r\n\r\nnonebot_plugin_blive_danmaku\r\n\r\n**插件项目仓库/主页链接:**\r\n\r\nhttps://github.com/zangxx66/nonebot_plugin_blive_danmaku\r\n\r\n**标签:**\r\n\r\n[{\"label\":\"bilibili\",\"color\":\"#EA5252\"}]\r\n",
+ "closed_at": null,
+ "comments": 1,
+ "comments_url": "https://api.github.com/repos/he0119/action-test/issues/101/comments",
+ "created_at": "2023-04-10T00:45:12Z",
+ "events_url": "https://api.github.com/repos/he0119/action-test/issues/101/events",
+ "html_url": "https://github.com/he0119/action-test/issues/101",
+ "id": 1660063814,
+ "labels": [
+ {
+ "color": "d73a4a",
+ "default": true,
+ "description": "Something isn't working",
+ "id": 2533455592,
+ "name": "bug",
+ "node_id": "MDU6TGFiZWwyNTMzNDU1NTky",
+ "url": "https://api.github.com/repos/he0119/action-test/labels/bug"
+ },
+ {
+ "color": "2A2219",
+ "default": false,
+ "description": "",
+ "id": 2798075966,
+ "name": "Plugin",
+ "node_id": "MDU6TGFiZWwyNzk4MDc1OTY2",
+ "url": "https://api.github.com/repos/he0119/action-test/labels/Plugin"
+ }
+ ],
+ "labels_url": "https://api.github.com/repos/he0119/action-test/issues/101/labels{/name}",
+ "locked": false,
+ "milestone": null,
+ "node_id": "I_kwDOEtTRZs5i8pBG",
+ "number": 101,
+ "performed_via_github_app": null,
+ "reactions": {
+ "+1": 0,
+ "-1": 0,
+ "confused": 0,
+ "eyes": 0,
+ "heart": 0,
+ "hooray": 0,
+ "laugh": 0,
+ "rocket": 0,
+ "total_count": 0,
+ "url": "https://api.github.com/repos/he0119/action-test/issues/101/reactions"
+ },
+ "repository_url": "https://api.github.com/repos/he0119/action-test",
+ "state": "open",
+ "state_reason": null,
+ "timeline_url": "https://api.github.com/repos/he0119/action-test/issues/101/timeline",
+ "title": "Plugin: B站直播间路灯",
+ "updated_at": "2023-04-10T00:46:25Z",
+ "url": "https://api.github.com/repos/he0119/action-test/issues/101",
+ "user": {
+ "avatar_url": "https://avatars.githubusercontent.com/u/5219550?v=4",
+ "events_url": "https://api.github.com/users/he0119/events{/privacy}",
+ "followers_url": "https://api.github.com/users/he0119/followers",
+ "following_url": "https://api.github.com/users/he0119/following{/other_user}",
+ "gists_url": "https://api.github.com/users/he0119/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/he0119",
+ "id": 5219550,
+ "login": "he0119",
+ "node_id": "MDQ6VXNlcjUyMTk1NTA=",
+ "organizations_url": "https://api.github.com/users/he0119/orgs",
+ "received_events_url": "https://api.github.com/users/he0119/received_events",
+ "repos_url": "https://api.github.com/users/he0119/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/he0119/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/he0119/subscriptions",
+ "type": "User",
+ "url": "https://api.github.com/users/he0119"
+ }
+ },
+ "repository": {
+ "allow_forking": true,
+ "archive_url": "https://api.github.com/repos/he0119/action-test/{archive_format}{/ref}",
+ "archived": false,
+ "assignees_url": "https://api.github.com/repos/he0119/action-test/assignees{/user}",
+ "blobs_url": "https://api.github.com/repos/he0119/action-test/git/blobs{/sha}",
+ "branches_url": "https://api.github.com/repos/he0119/action-test/branches{/branch}",
+ "clone_url": "https://github.com/he0119/action-test.git",
+ "collaborators_url": "https://api.github.com/repos/he0119/action-test/collaborators{/collaborator}",
+ "comments_url": "https://api.github.com/repos/he0119/action-test/comments{/number}",
+ "commits_url": "https://api.github.com/repos/he0119/action-test/commits{/sha}",
+ "compare_url": "https://api.github.com/repos/he0119/action-test/compare/{base}...{head}",
+ "contents_url": "https://api.github.com/repos/he0119/action-test/contents/{+path}",
+ "contributors_url": "https://api.github.com/repos/he0119/action-test/contributors",
+ "created_at": "2020-11-25T12:46:10Z",
+ "default_branch": "main",
+ "deployments_url": "https://api.github.com/repos/he0119/action-test/deployments",
+ "description": "测试操作",
+ "disabled": false,
+ "downloads_url": "https://api.github.com/repos/he0119/action-test/downloads",
+ "events_url": "https://api.github.com/repos/he0119/action-test/events",
+ "fork": false,
+ "forks": 1,
+ "forks_count": 1,
+ "forks_url": "https://api.github.com/repos/he0119/action-test/forks",
+ "full_name": "he0119/action-test",
+ "git_commits_url": "https://api.github.com/repos/he0119/action-test/git/commits{/sha}",
+ "git_refs_url": "https://api.github.com/repos/he0119/action-test/git/refs{/sha}",
+ "git_tags_url": "https://api.github.com/repos/he0119/action-test/git/tags{/sha}",
+ "git_url": "git://github.com/he0119/action-test.git",
+ "has_discussions": true,
+ "has_downloads": true,
+ "has_issues": true,
+ "has_pages": false,
+ "has_projects": true,
+ "has_wiki": true,
+ "homepage": null,
+ "hooks_url": "https://api.github.com/repos/he0119/action-test/hooks",
+ "html_url": "https://github.com/he0119/action-test",
+ "id": 315937126,
+ "is_template": false,
+ "issue_comment_url": "https://api.github.com/repos/he0119/action-test/issues/comments{/number}",
+ "issue_events_url": "https://api.github.com/repos/he0119/action-test/issues/events{/number}",
+ "issues_url": "https://api.github.com/repos/he0119/action-test/issues{/number}",
+ "keys_url": "https://api.github.com/repos/he0119/action-test/keys{/key_id}",
+ "labels_url": "https://api.github.com/repos/he0119/action-test/labels{/name}",
+ "language": "Python",
+ "languages_url": "https://api.github.com/repos/he0119/action-test/languages",
+ "license": {
+ "key": "mit",
+ "name": "MIT License",
+ "node_id": "MDc6TGljZW5zZTEz",
+ "spdx_id": "MIT",
+ "url": "https://api.github.com/licenses/mit"
+ },
+ "merges_url": "https://api.github.com/repos/he0119/action-test/merges",
+ "milestones_url": "https://api.github.com/repos/he0119/action-test/milestones{/number}",
+ "mirror_url": null,
+ "name": "action-test",
+ "node_id": "MDEwOlJlcG9zaXRvcnkzMTU5MzcxMjY=",
+ "notifications_url": "https://api.github.com/repos/he0119/action-test/notifications{?since,all,participating}",
+ "open_issues": 1,
+ "open_issues_count": 1,
+ "owner": {
+ "avatar_url": "https://avatars.githubusercontent.com/u/5219550?v=4",
+ "events_url": "https://api.github.com/users/he0119/events{/privacy}",
+ "followers_url": "https://api.github.com/users/he0119/followers",
+ "following_url": "https://api.github.com/users/he0119/following{/other_user}",
+ "gists_url": "https://api.github.com/users/he0119/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/he0119",
+ "id": 5219550,
+ "login": "he0119",
+ "node_id": "MDQ6VXNlcjUyMTk1NTA=",
+ "organizations_url": "https://api.github.com/users/he0119/orgs",
+ "received_events_url": "https://api.github.com/users/he0119/received_events",
+ "repos_url": "https://api.github.com/users/he0119/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/he0119/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/he0119/subscriptions",
+ "type": "User",
+ "url": "https://api.github.com/users/he0119"
+ },
+ "private": false,
+ "pulls_url": "https://api.github.com/repos/he0119/action-test/pulls{/number}",
+ "pushed_at": "2023-04-08T14:30:15Z",
+ "releases_url": "https://api.github.com/repos/he0119/action-test/releases{/id}",
+ "size": 143,
+ "ssh_url": "git@github.com:he0119/action-test.git",
+ "stargazers_count": 0,
+ "stargazers_url": "https://api.github.com/repos/he0119/action-test/stargazers",
+ "statuses_url": "https://api.github.com/repos/he0119/action-test/statuses/{sha}",
+ "subscribers_url": "https://api.github.com/repos/he0119/action-test/subscribers",
+ "subscription_url": "https://api.github.com/repos/he0119/action-test/subscription",
+ "svn_url": "https://github.com/he0119/action-test",
+ "tags_url": "https://api.github.com/repos/he0119/action-test/tags",
+ "teams_url": "https://api.github.com/repos/he0119/action-test/teams",
+ "topics": [],
+ "trees_url": "https://api.github.com/repos/he0119/action-test/git/trees{/sha}",
+ "updated_at": "2023-01-31T18:36:54Z",
+ "url": "https://api.github.com/repos/he0119/action-test",
+ "visibility": "public",
+ "watchers": 0,
+ "watchers_count": 0,
+ "web_commit_signoff_required": false
+ },
+ "sender": {
+ "avatar_url": "https://avatars.githubusercontent.com/u/5219550?v=4",
+ "events_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/events{/privacy}",
+ "followers_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/followers",
+ "following_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/following{/other_user}",
+ "gists_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/apps/noneflow-test",
+ "id": 130064678,
+ "login": "noneflow-test[bot]",
+ "node_id": "BOT_kgDOB8ChJg",
+ "organizations_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/orgs",
+ "received_events_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/received_events",
+ "repos_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/noneflow-test%5Bbot%5D/subscriptions",
+ "type": "Bot",
+ "url": "https://api.github.com/users/noneflow-test%5Bbot%5D"
+ }
+}
\ No newline at end of file
diff --git a/tests/publish/process/test_publish_check.py b/tests/publish/process/test_publish_check.py
index f0c20a12..8bb01c36 100644
--- a/tests/publish/process/test_publish_check.py
+++ b/tests/publish/process/test_publish_check.py
@@ -668,3 +668,32 @@ async def test_not_publish_issue(app: App, mocker: MockerFixture) -> None:
check=True,
capture_output=True,
)
+
+
+async def test_comment_by_self(app: App, mocker: MockerFixture) -> None:
+ """测试自己评论触发的情况"""
+ from src.plugins.publish import publish_check_matcher
+
+ mock_httpx = mocker.patch("httpx.get", side_effect=mocked_httpx_get)
+ mock_subprocess_run = mocker.patch(
+ "subprocess.run", side_effect=lambda *args, **kwargs: mocker.MagicMock()
+ )
+
+ async with app.test_matcher(publish_check_matcher) as ctx:
+ adapter = get_adapter(Adapter)
+ bot = ctx.create_bot(
+ base=GitHubBot,
+ adapter=adapter,
+ self_id=GitHubApp(app_id="1", private_key="1"), # type: ignore
+ )
+ bot = cast(GitHubBot, bot)
+ event_path = (
+ Path(__file__).parent.parent / "plugin-test" / "issue-comment-bot.json"
+ )
+ event = Adapter.payload_to_event("1", "issue_comment", event_path.read_bytes())
+ assert isinstance(event, IssueCommentCreated)
+
+ ctx.receive_event(bot, event)
+
+ mock_httpx.assert_not_called()
+ mock_subprocess_run.assert_not_called()