Skip to content

Commit 6ec6b47

Browse files
authored
Merge pull request #126 from sewenthy/sewen/121-ignore-code-comments-from-defined-list-of-users
Ignore code comments from defined list of users
2 parents 56ada10 + 8837244 commit 6ec6b47

File tree

6 files changed

+269
-1
lines changed

6 files changed

+269
-1
lines changed

documentation/config_docs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks
1515
```json
1616
{
1717
"main_branch_name": "develop",
18+
"ignored_users": [
19+
"ignored_user"
20+
],
1821
"prefix_rules": {
1922
...
2023
},
@@ -37,6 +40,7 @@ Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks
3740
| `prefix_rules` | prefix rules config object | required field |
3841
| `status_rules` | status rules config object | all status notifications are ignored |
3942
| `project_owners` | project owners config object | no project owners are defined |
43+
| `ignored_users` | list of users to be ignored on all notifications | no user is ignored |
4044

4145
## Label Options
4246

lib/action.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,28 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
155155
)
156156
)
157157

158-
let generate_notifications (ctx : Context.t) req =
158+
let ignore_notifications_from_user cfg req =
159+
let sender_login =
160+
match req with
161+
| Github.Push n -> Some n.sender.login
162+
| Pull_request n -> Some n.sender.login
163+
| PR_review n -> Some n.sender.login
164+
| PR_review_comment n -> Some n.sender.login
165+
| Issue n -> Some n.sender.login
166+
| Issue_comment n -> Some n.sender.login
167+
| Commit_comment n -> Some n.sender.login
168+
| _ -> None
169+
in
170+
match sender_login with
171+
| Some sender_login -> List.exists cfg.ignored_users ~f:(String.equal sender_login)
172+
| None -> false
173+
174+
let generate_notifications (ctx : Context.t) (req : Github.t) =
159175
let repo = Github.repo_of_notification req in
160176
let cfg = Context.find_repo_config_exn ctx repo.url in
177+
match ignore_notifications_from_user cfg req with
178+
| true -> Lwt.return []
179+
| false ->
161180
match req with
162181
| Github.Push n ->
163182
partition_push cfg n |> List.map ~f:(fun (channel, n) -> generate_push_notification n channel) |> Lwt.return

lib/config.atd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type config = {
3535
label_rules : label_rules;
3636
~status_rules <ocaml default="{allowed_pipelines = Some []; rules = []}"> : status_rules;
3737
~project_owners <ocaml default="{rules = []}"> : project_owners;
38+
~ignored_users <ocaml default="[]">: string list; (* list of ignored users *)
3839
?main_branch_name : string nullable; (* the name of the main branch; used to filter out notifications about merges of main branch into other branches *)
3940
}
4041

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
{
2+
"action": "created",
3+
"issue": {
4+
"url": "https://api.github.com/repos/sewenthy/monorobot/issues/1",
5+
"repository_url": "https://api.github.com/repos/sewenthy/monorobot",
6+
"labels_url": "https://api.github.com/repos/sewenthy/monorobot/issues/1/labels{/name}",
7+
"comments_url": "https://api.github.com/repos/sewenthy/monorobot/issues/1/comments",
8+
"events_url": "https://api.github.com/repos/sewenthy/monorobot/issues/1/events",
9+
"html_url": "https://github.com/sewenthy/monorobot/pull/1",
10+
"id": 1417857388,
11+
"node_id": "PR_kwDOIRbPmc5BQvSE",
12+
"number": 1,
13+
"title": "something test",
14+
"user": {
15+
"login": "sewenthy",
16+
"id": 23148113,
17+
"node_id": "MDQ6VXNlcjIzMTQ4MTEz",
18+
"avatar_url": "https://avatars.githubusercontent.com/u/23148113?v=4",
19+
"gravatar_id": "",
20+
"url": "https://api.github.com/users/sewenthy",
21+
"html_url": "https://github.com/sewenthy",
22+
"followers_url": "https://api.github.com/users/sewenthy/followers",
23+
"following_url": "https://api.github.com/users/sewenthy/following{/other_user}",
24+
"gists_url": "https://api.github.com/users/sewenthy/gists{/gist_id}",
25+
"starred_url": "https://api.github.com/users/sewenthy/starred{/owner}{/repo}",
26+
"subscriptions_url": "https://api.github.com/users/sewenthy/subscriptions",
27+
"organizations_url": "https://api.github.com/users/sewenthy/orgs",
28+
"repos_url": "https://api.github.com/users/sewenthy/repos",
29+
"events_url": "https://api.github.com/users/sewenthy/events{/privacy}",
30+
"received_events_url": "https://api.github.com/users/sewenthy/received_events",
31+
"type": "User",
32+
"site_admin": false
33+
},
34+
"labels": [
35+
36+
],
37+
"state": "open",
38+
"locked": false,
39+
"assignee": null,
40+
"assignees": [
41+
42+
],
43+
"milestone": null,
44+
"comments": 1,
45+
"created_at": "2022-10-21T07:04:00Z",
46+
"updated_at": "2022-10-21T07:04:47Z",
47+
"closed_at": null,
48+
"author_association": "OWNER",
49+
"active_lock_reason": null,
50+
"draft": false,
51+
"pull_request": {
52+
"url": "https://api.github.com/repos/sewenthy/monorobot/pulls/1",
53+
"html_url": "https://github.com/sewenthy/monorobot/pull/1",
54+
"diff_url": "https://github.com/sewenthy/monorobot/pull/1.diff",
55+
"patch_url": "https://github.com/sewenthy/monorobot/pull/1.patch",
56+
"merged_at": null
57+
},
58+
"body": "## Description of the task\r\n\r\nPlease describe the task related to this PR. Or the reason behind the\r\nchange.\r\n\r\n## How to test\r\n\r\nHow to test the changes? Which command to run? Which output is expected?\r\n\r\n```\r\n./monorobot check mock_payloads/SOME_FILE\r\n```\r\n\r\n## References\r\n\r\n- existing issue:\r\n- Slack discussion:\r\n- other?\r\n",
59+
"reactions": {
60+
"url": "https://api.github.com/repos/sewenthy/monorobot/issues/1/reactions",
61+
"total_count": 0,
62+
"+1": 0,
63+
"-1": 0,
64+
"laugh": 0,
65+
"hooray": 0,
66+
"confused": 0,
67+
"heart": 0,
68+
"rocket": 0,
69+
"eyes": 0
70+
},
71+
"timeline_url": "https://api.github.com/repos/sewenthy/monorobot/issues/1/timeline",
72+
"performed_via_github_app": null,
73+
"state_reason": null
74+
},
75+
"comment": {
76+
"url": "https://api.github.com/repos/sewenthy/monorobot/issues/comments/1286545775",
77+
"html_url": "https://github.com/sewenthy/monorobot/pull/1#issuecomment-1286545775",
78+
"issue_url": "https://api.github.com/repos/sewenthy/monorobot/issues/1",
79+
"id": 1286545775,
80+
"node_id": "IC_kwDOIRbPmc5MryFv",
81+
"user": {
82+
"login": "ignored_user",
83+
"id": 23148113,
84+
"node_id": "MDQ6VXNlcjIzMTQ4MTEz",
85+
"avatar_url": "https://avatars.githubusercontent.com/u/23148113?v=4",
86+
"gravatar_id": "",
87+
"url": "https://api.github.com/users/ignored_user",
88+
"html_url": "https://github.com/ignored_user",
89+
"followers_url": "https://api.github.com/users/ignored_user/followers",
90+
"following_url": "https://api.github.com/users/ignored_user/following{/other_user}",
91+
"gists_url": "https://api.github.com/users/ignored_user/gists{/gist_id}",
92+
"starred_url": "https://api.github.com/users/ignored_user/starred{/owner}{/repo}",
93+
"subscriptions_url": "https://api.github.com/users/ignored_user/subscriptions",
94+
"organizations_url": "https://api.github.com/users/ignored_user/orgs",
95+
"repos_url": "https://api.github.com/users/ignored_user/repos",
96+
"events_url": "https://api.github.com/users/ignored_user/events{/privacy}",
97+
"received_events_url": "https://api.github.com/users/ignored_user/received_events",
98+
"type": "User",
99+
"site_admin": false
100+
},
101+
"created_at": "2022-10-21T07:04:46Z",
102+
"updated_at": "2022-10-21T07:04:46Z",
103+
"author_association": "OWNER",
104+
"body": "new comment\r\n",
105+
"reactions": {
106+
"url": "https://api.github.com/repos/sewenthy/monorobot/issues/comments/1286545775/reactions",
107+
"total_count": 0,
108+
"+1": 0,
109+
"-1": 0,
110+
"laugh": 0,
111+
"hooray": 0,
112+
"confused": 0,
113+
"heart": 0,
114+
"rocket": 0,
115+
"eyes": 0
116+
},
117+
"performed_via_github_app": null
118+
},
119+
"repository": {
120+
"id": 555143065,
121+
"node_id": "R_kgDOIRbPmQ",
122+
"name": "monorobot",
123+
"full_name": "sewenthy/monorobot",
124+
"private": false,
125+
"owner": {
126+
"login": "sewenthy",
127+
"id": 23148113,
128+
"node_id": "MDQ6VXNlcjIzMTQ4MTEz",
129+
"avatar_url": "https://avatars.githubusercontent.com/u/23148113?v=4",
130+
"gravatar_id": "",
131+
"url": "https://api.github.com/users/sewenthy",
132+
"html_url": "https://github.com/sewenthy",
133+
"followers_url": "https://api.github.com/users/sewenthy/followers",
134+
"following_url": "https://api.github.com/users/sewenthy/following{/other_user}",
135+
"gists_url": "https://api.github.com/users/sewenthy/gists{/gist_id}",
136+
"starred_url": "https://api.github.com/users/sewenthy/starred{/owner}{/repo}",
137+
"subscriptions_url": "https://api.github.com/users/sewenthy/subscriptions",
138+
"organizations_url": "https://api.github.com/users/sewenthy/orgs",
139+
"repos_url": "https://api.github.com/users/sewenthy/repos",
140+
"events_url": "https://api.github.com/users/sewenthy/events{/privacy}",
141+
"received_events_url": "https://api.github.com/users/sewenthy/received_events",
142+
"type": "User",
143+
"site_admin": false
144+
},
145+
"html_url": "https://github.com/sewenthy/monorobot",
146+
"description": "github monorepo bot - configurable directory tree notifications in slack",
147+
"fork": true,
148+
"url": "https://api.github.com/repos/sewenthy/monorobot",
149+
"forks_url": "https://api.github.com/repos/sewenthy/monorobot/forks",
150+
"keys_url": "https://api.github.com/repos/sewenthy/monorobot/keys{/key_id}",
151+
"collaborators_url": "https://api.github.com/repos/sewenthy/monorobot/collaborators{/collaborator}",
152+
"teams_url": "https://api.github.com/repos/sewenthy/monorobot/teams",
153+
"hooks_url": "https://api.github.com/repos/sewenthy/monorobot/hooks",
154+
"issue_events_url": "https://api.github.com/repos/sewenthy/monorobot/issues/events{/number}",
155+
"events_url": "https://api.github.com/repos/sewenthy/monorobot/events",
156+
"assignees_url": "https://api.github.com/repos/sewenthy/monorobot/assignees{/user}",
157+
"branches_url": "https://api.github.com/repos/sewenthy/monorobot/branches{/branch}",
158+
"tags_url": "https://api.github.com/repos/sewenthy/monorobot/tags",
159+
"blobs_url": "https://api.github.com/repos/sewenthy/monorobot/git/blobs{/sha}",
160+
"git_tags_url": "https://api.github.com/repos/sewenthy/monorobot/git/tags{/sha}",
161+
"git_refs_url": "https://api.github.com/repos/sewenthy/monorobot/git/refs{/sha}",
162+
"trees_url": "https://api.github.com/repos/sewenthy/monorobot/git/trees{/sha}",
163+
"statuses_url": "https://api.github.com/repos/sewenthy/monorobot/statuses/{sha}",
164+
"languages_url": "https://api.github.com/repos/sewenthy/monorobot/languages",
165+
"stargazers_url": "https://api.github.com/repos/sewenthy/monorobot/stargazers",
166+
"contributors_url": "https://api.github.com/repos/sewenthy/monorobot/contributors",
167+
"subscribers_url": "https://api.github.com/repos/sewenthy/monorobot/subscribers",
168+
"subscription_url": "https://api.github.com/repos/sewenthy/monorobot/subscription",
169+
"commits_url": "https://api.github.com/repos/sewenthy/monorobot/commits{/sha}",
170+
"git_commits_url": "https://api.github.com/repos/sewenthy/monorobot/git/commits{/sha}",
171+
"comments_url": "https://api.github.com/repos/sewenthy/monorobot/comments{/number}",
172+
"issue_comment_url": "https://api.github.com/repos/sewenthy/monorobot/issues/comments{/number}",
173+
"contents_url": "https://api.github.com/repos/sewenthy/monorobot/contents/{+path}",
174+
"compare_url": "https://api.github.com/repos/sewenthy/monorobot/compare/{base}...{head}",
175+
"merges_url": "https://api.github.com/repos/sewenthy/monorobot/merges",
176+
"archive_url": "https://api.github.com/repos/sewenthy/monorobot/{archive_format}{/ref}",
177+
"downloads_url": "https://api.github.com/repos/sewenthy/monorobot/downloads",
178+
"issues_url": "https://api.github.com/repos/sewenthy/monorobot/issues{/number}",
179+
"pulls_url": "https://api.github.com/repos/sewenthy/monorobot/pulls{/number}",
180+
"milestones_url": "https://api.github.com/repos/sewenthy/monorobot/milestones{/number}",
181+
"notifications_url": "https://api.github.com/repos/sewenthy/monorobot/notifications{?since,all,participating}",
182+
"labels_url": "https://api.github.com/repos/sewenthy/monorobot/labels{/name}",
183+
"releases_url": "https://api.github.com/repos/sewenthy/monorobot/releases{/id}",
184+
"deployments_url": "https://api.github.com/repos/sewenthy/monorobot/deployments",
185+
"created_at": "2022-10-21T02:48:23Z",
186+
"updated_at": "2022-10-21T05:04:57Z",
187+
"pushed_at": "2022-10-21T07:04:00Z",
188+
"git_url": "git://github.com/sewenthy/monorobot.git",
189+
"ssh_url": "[email protected]:sewenthy/monorobot.git",
190+
"clone_url": "https://github.com/sewenthy/monorobot.git",
191+
"svn_url": "https://github.com/sewenthy/monorobot",
192+
"homepage": "",
193+
"size": 653,
194+
"stargazers_count": 0,
195+
"watchers_count": 0,
196+
"language": "OCaml",
197+
"has_issues": false,
198+
"has_projects": true,
199+
"has_downloads": true,
200+
"has_wiki": true,
201+
"has_pages": false,
202+
"forks_count": 0,
203+
"mirror_url": null,
204+
"archived": false,
205+
"disabled": false,
206+
"open_issues_count": 1,
207+
"license": null,
208+
"allow_forking": true,
209+
"is_template": false,
210+
"web_commit_signoff_required": false,
211+
"topics": [
212+
213+
],
214+
"visibility": "public",
215+
"forks": 0,
216+
"open_issues": 1,
217+
"watchers": 0,
218+
"default_branch": "master"
219+
},
220+
"sender": {
221+
"login": "ignored_user",
222+
"id": 23148113,
223+
"node_id": "MDQ6VXNlcjIzMTQ4MTEz",
224+
"avatar_url": "https://avatars.githubusercontent.com/u/23148113?v=4",
225+
"gravatar_id": "",
226+
"url": "https://api.github.com/users/ignored_user",
227+
"html_url": "https://github.com/ignored_user",
228+
"followers_url": "https://api.github.com/users/ignored_user/followers",
229+
"following_url": "https://api.github.com/users/ignored_user/following{/other_user}",
230+
"gists_url": "https://api.github.com/users/ignored_user/gists{/gist_id}",
231+
"starred_url": "https://api.github.com/users/ignored_user/starred{/owner}{/repo}",
232+
"subscriptions_url": "https://api.github.com/users/ignored_user/subscriptions",
233+
"organizations_url": "https://api.github.com/users/ignored_user/orgs",
234+
"repos_url": "https://api.github.com/users/ignored_user/repos",
235+
"events_url": "https://api.github.com/users/ignored_user/events{/privacy}",
236+
"received_events_url": "https://api.github.com/users/ignored_user/received_events",
237+
"type": "User",
238+
"site_admin": false
239+
}
240+
}

test/monorobot.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
}
1919
]
2020
},
21+
"ignored_users": [
22+
"ignored_user"
23+
],
2124
"prefix_rules": {
2225
"default_channel": "default",
2326
"filter_main_branch": true,

test/slack_payloads.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ will notify #default
127127
}
128128
]
129129
}
130+
===== file ../mock_payloads/issue_comment.created_in_issue_by_ignored.json =====
130131
===== file ../mock_payloads/issue_comment.created_in_pr.json =====
131132
will notify #a1-bot
132133
{

0 commit comments

Comments
 (0)