Skip to content

Commit 8837244

Browse files
committed
cfg and action: add support to ignore comments from certain users
1 parent 858b5e1 commit 8837244

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
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

test/monorobot.json

Lines changed: 3 additions & 3 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,
@@ -64,9 +67,6 @@
6467
},
6568
"label_rules": {
6669
"default_channel": "default",
67-
"ignored_users": [
68-
"ignored_user"
69-
],
7070
"rules": [
7171
{
7272
"match": [

test/slack_payloads.expected

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ will notify #default
128128
]
129129
}
130130
===== file ../mock_payloads/issue_comment.created_in_issue_by_ignored.json =====
131-
will notify #default
132-
{
133-
"channel": "default",
134-
"text": "<https://github.com/sewenthy/monorobot|[sewenthy/monorobot]> *ignored_user* <https://github.com/sewenthy/monorobot/pull/1#issuecomment-1286545775|commented> on #1 <https://github.com/sewenthy/monorobot/pull/1|something test>",
135-
"attachments": [
136-
{
137-
"fallback": null,
138-
"mrkdwn_in": [ "text" ],
139-
"color": "#ccc",
140-
"text": "new comment"
141-
}
142-
]
143-
}
144131
===== file ../mock_payloads/issue_comment.created_in_pr.json =====
145132
will notify #a1-bot
146133
{

0 commit comments

Comments
 (0)