Skip to content

Commit

Permalink
Fix/filter robot created issue (#258)
Browse files Browse the repository at this point in the history
- 如果 issue 是机器人创建的,也不要评论。
  • Loading branch information
RaoHai authored Aug 24, 2024
2 parents 6d1a8ee + c190009 commit 58cd01a
Show file tree
Hide file tree
Showing 9 changed files with 3,638 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/event_handler/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_issue(self) -> Tuple[Issue, Repository]:
async def execute(self):
try:
print("actions:", self.event["action"])
if self.event['sender']['type'] == "Bot":
return {"success": True}

if self.event["action"] == "opened":
issue, repo = self.get_issue()

Expand Down
249 changes: 249 additions & 0 deletions server/tests/fixtures/github/events/issue/comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"event": "issue_comment",
"payload": {
"action": "created",
"issue": {
"url": "https://api.github.com/repos/petercat-ai/demo/issues/33",
"repository_url": "https://api.github.com/repos/petercat-ai/demo",
"labels_url": "https://api.github.com/repos/petercat-ai/demo/issues/33/labels{/name}",
"comments_url": "https://api.github.com/repos/petercat-ai/demo/issues/33/comments",
"events_url": "https://api.github.com/repos/petercat-ai/demo/issues/33/events",
"html_url": "https://github.com/petercat-ai/demo/issues/33",
"id": 2484539296,
"node_id": "I_kwDOMl4Nsc6UFw-g",
"number": 33,
"title": "Demo 用例 1: 新建 issue",
"user": {
"login": "RaoHai",
"id": 566097,
"node_id": "MDQ6VXNlcjU2NjA5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/566097?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RaoHai",
"html_url": "https://github.com/RaoHai",
"followers_url": "https://api.github.com/users/RaoHai/followers",
"following_url": "https://api.github.com/users/RaoHai/following{/other_user}",
"gists_url": "https://api.github.com/users/RaoHai/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RaoHai/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RaoHai/subscriptions",
"organizations_url": "https://api.github.com/users/RaoHai/orgs",
"repos_url": "https://api.github.com/users/RaoHai/repos",
"events_url": "https://api.github.com/users/RaoHai/events{/privacy}",
"received_events_url": "https://api.github.com/users/RaoHai/received_events",
"type": "User",
"site_admin": false
},
"labels": [],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [],
"milestone": null,
"comments": 2,
"created_at": "2024-08-24T12:02:40Z",
"updated_at": "2024-08-24T12:13:47Z",
"closed_at": null,
"author_association": "NONE",
"active_lock_reason": null,
"body": "这是 issue 内容",
"reactions": {
"url": "https://api.github.com/repos/petercat-ai/demo/issues/33/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/petercat-ai/demo/issues/33/timeline",
"performed_via_github_app": null,
"state_reason": null
},
"comment": {
"url": "https://api.github.com/repos/petercat-ai/demo/issues/comments/2308374057",
"html_url": "https://github.com/petercat-ai/demo/issues/33#issuecomment-2308374057",
"issue_url": "https://api.github.com/repos/petercat-ai/demo/issues/33",
"id": 2308374057,
"node_id": "IC_kwDOMl4Nsc6Jlv4p",
"user": {
"login": "RaoHai",
"id": 566097,
"node_id": "MDQ6VXNlcjU2NjA5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/566097?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RaoHai",
"html_url": "https://github.com/RaoHai",
"followers_url": "https://api.github.com/users/RaoHai/followers",
"following_url": "https://api.github.com/users/RaoHai/following{/other_user}",
"gists_url": "https://api.github.com/users/RaoHai/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RaoHai/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RaoHai/subscriptions",
"organizations_url": "https://api.github.com/users/RaoHai/orgs",
"repos_url": "https://api.github.com/users/RaoHai/repos",
"events_url": "https://api.github.com/users/RaoHai/events{/privacy}",
"received_events_url": "https://api.github.com/users/RaoHai/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2024-08-24T12:13:46Z",
"updated_at": "2024-08-24T12:13:46Z",
"author_association": "NONE",
"body": "这是 at 了人的评论 @RaoHai ",
"reactions": {
"url": "https://api.github.com/repos/petercat-ai/demo/issues/comments/2308374057/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"performed_via_github_app": null
},
"repository": {
"id": 845024689,
"node_id": "R_kgDOMl4NsQ",
"name": "demo",
"full_name": "petercat-ai/demo",
"private": true,
"owner": {
"login": "petercat-ai",
"id": 169796403,
"node_id": "O_kgDOCh7jMw",
"avatar_url": "https://avatars.githubusercontent.com/u/169796403?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/petercat-ai",
"html_url": "https://github.com/petercat-ai",
"followers_url": "https://api.github.com/users/petercat-ai/followers",
"following_url": "https://api.github.com/users/petercat-ai/following{/other_user}",
"gists_url": "https://api.github.com/users/petercat-ai/gists{/gist_id}",
"starred_url": "https://api.github.com/users/petercat-ai/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/petercat-ai/subscriptions",
"organizations_url": "https://api.github.com/users/petercat-ai/orgs",
"repos_url": "https://api.github.com/users/petercat-ai/repos",
"events_url": "https://api.github.com/users/petercat-ai/events{/privacy}",
"received_events_url": "https://api.github.com/users/petercat-ai/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/petercat-ai/demo",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/petercat-ai/demo",
"forks_url": "https://api.github.com/repos/petercat-ai/demo/forks",
"keys_url": "https://api.github.com/repos/petercat-ai/demo/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/petercat-ai/demo/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/petercat-ai/demo/teams",
"hooks_url": "https://api.github.com/repos/petercat-ai/demo/hooks",
"issue_events_url": "https://api.github.com/repos/petercat-ai/demo/issues/events{/number}",
"events_url": "https://api.github.com/repos/petercat-ai/demo/events",
"assignees_url": "https://api.github.com/repos/petercat-ai/demo/assignees{/user}",
"branches_url": "https://api.github.com/repos/petercat-ai/demo/branches{/branch}",
"tags_url": "https://api.github.com/repos/petercat-ai/demo/tags",
"blobs_url": "https://api.github.com/repos/petercat-ai/demo/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/petercat-ai/demo/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/petercat-ai/demo/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/petercat-ai/demo/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/petercat-ai/demo/statuses/{sha}",
"languages_url": "https://api.github.com/repos/petercat-ai/demo/languages",
"stargazers_url": "https://api.github.com/repos/petercat-ai/demo/stargazers",
"contributors_url": "https://api.github.com/repos/petercat-ai/demo/contributors",
"subscribers_url": "https://api.github.com/repos/petercat-ai/demo/subscribers",
"subscription_url": "https://api.github.com/repos/petercat-ai/demo/subscription",
"commits_url": "https://api.github.com/repos/petercat-ai/demo/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/petercat-ai/demo/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/petercat-ai/demo/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/petercat-ai/demo/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/petercat-ai/demo/contents/{+path}",
"compare_url": "https://api.github.com/repos/petercat-ai/demo/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/petercat-ai/demo/merges",
"archive_url": "https://api.github.com/repos/petercat-ai/demo/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/petercat-ai/demo/downloads",
"issues_url": "https://api.github.com/repos/petercat-ai/demo/issues{/number}",
"pulls_url": "https://api.github.com/repos/petercat-ai/demo/pulls{/number}",
"milestones_url": "https://api.github.com/repos/petercat-ai/demo/milestones{/number}",
"notifications_url": "https://api.github.com/repos/petercat-ai/demo/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/petercat-ai/demo/labels{/name}",
"releases_url": "https://api.github.com/repos/petercat-ai/demo/releases{/id}",
"deployments_url": "https://api.github.com/repos/petercat-ai/demo/deployments",
"created_at": "2024-08-20T12:41:42Z",
"updated_at": "2024-08-24T07:13:52Z",
"pushed_at": "2024-08-20T12:41:42Z",
"git_url": "git://github.com/petercat-ai/demo.git",
"ssh_url": "[email protected]:petercat-ai/demo.git",
"clone_url": "https://github.com/petercat-ai/demo.git",
"svn_url": "https://github.com/petercat-ai/demo",
"homepage": null,
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": true,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 4,
"license": null,
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "private",
"forks": 0,
"open_issues": 4,
"watchers": 0,
"default_branch": "main",
"custom_properties": {}
},
"organization": {
"login": "petercat-ai",
"id": 169796403,
"node_id": "O_kgDOCh7jMw",
"url": "https://api.github.com/orgs/petercat-ai",
"repos_url": "https://api.github.com/orgs/petercat-ai/repos",
"events_url": "https://api.github.com/orgs/petercat-ai/events",
"hooks_url": "https://api.github.com/orgs/petercat-ai/hooks",
"issues_url": "https://api.github.com/orgs/petercat-ai/issues",
"members_url": "https://api.github.com/orgs/petercat-ai/members{/member}",
"public_members_url": "https://api.github.com/orgs/petercat-ai/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/169796403?v=4",
"description": null
},
"sender": {
"login": "RaoHai",
"id": 566097,
"node_id": "MDQ6VXNlcjU2NjA5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/566097?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RaoHai",
"html_url": "https://github.com/RaoHai",
"followers_url": "https://api.github.com/users/RaoHai/followers",
"following_url": "https://api.github.com/users/RaoHai/following{/other_user}",
"gists_url": "https://api.github.com/users/RaoHai/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RaoHai/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RaoHai/subscriptions",
"organizations_url": "https://api.github.com/users/RaoHai/orgs",
"repos_url": "https://api.github.com/users/RaoHai/repos",
"events_url": "https://api.github.com/users/RaoHai/events{/privacy}",
"received_events_url": "https://api.github.com/users/RaoHai/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 54106016,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNTQxMDYwMTY="
}
}
}
Loading

0 comments on commit 58cd01a

Please sign in to comment.