@@ -5,6 +5,10 @@ open Mrkdwn
5
5
open Github_j
6
6
open Slack_j
7
7
8
+ type notify =
9
+ | New_message of Slack_t .post_message_req
10
+ | Update_message of Slack_t .update_message_req
11
+
8
12
let empty_attachments =
9
13
{
10
14
mrkdwn_in = None ;
@@ -55,21 +59,22 @@ let generate_pull_request_notification notification channel =
55
59
sprintf " <%s|[%s]> Pull request #%d %s %s by *%s*" repository.url repository.full_name number
56
60
(pp_link ~url: html_url title) action sender.login
57
61
in
58
- {
59
- channel;
60
- text = Some summary;
61
- attachments =
62
- Some
63
- [
64
- {
65
- empty_attachments with
66
- mrkdwn_in = Some [ " text" ];
67
- color = Some " #ccc" ;
68
- text = mrkdwn_of_markdown_opt body;
69
- };
70
- ];
71
- blocks = None ;
72
- }
62
+ New_message
63
+ {
64
+ channel;
65
+ text = Some summary;
66
+ attachments =
67
+ Some
68
+ [
69
+ {
70
+ empty_attachments with
71
+ mrkdwn_in = Some [ " text" ];
72
+ color = Some " #ccc" ;
73
+ text = mrkdwn_of_markdown_opt body;
74
+ };
75
+ ];
76
+ blocks = None ;
77
+ }
73
78
74
79
let generate_pr_review_notification notification channel =
75
80
let { action; sender; pull_request; review; repository } = notification in
@@ -93,28 +98,29 @@ let generate_pr_review_notification notification channel =
93
98
sprintf " <%s|[%s]> *%s* <%s|%s> #%d %s" repository.url repository.full_name sender.login review.html_url action_str
94
99
number (pp_link ~url: html_url title)
95
100
in
96
- {
97
- channel;
98
- text = Some summary;
99
- attachments =
100
- Some
101
- [
102
- {
103
- empty_attachments with
104
- mrkdwn_in = Some [ " text" ];
105
- color = Some " #ccc" ;
106
- text = mrkdwn_of_markdown_opt review.body;
107
- };
108
- ];
109
- blocks = None ;
110
- }
101
+ New_message
102
+ {
103
+ channel;
104
+ text = Some summary;
105
+ attachments =
106
+ Some
107
+ [
108
+ {
109
+ empty_attachments with
110
+ mrkdwn_in = Some [ " text" ];
111
+ color = Some " #ccc" ;
112
+ text = mrkdwn_of_markdown_opt review.body;
113
+ };
114
+ ];
115
+ blocks = None ;
116
+ }
111
117
112
- let generate_pr_review_comment_notification notification channel =
118
+ let generate_pr_review_comment_notification ( ctx : Context.t ) notification channel =
113
119
let { action; pull_request; sender; comment; repository } = notification in
114
120
let ({ number; title; html_url; _ } : pull_request ) = pull_request in
115
121
let action_str =
116
122
match action with
117
- | Created -> " commented"
123
+ | Created | Edited -> " commented"
118
124
| _ ->
119
125
invalid_arg
120
126
(sprintf " Monorobot doesn't know how to generate notification for the unexpected event %s"
@@ -130,22 +136,27 @@ let generate_pr_review_comment_notification notification channel =
130
136
| None -> None
131
137
| Some a -> Some (sprintf " New comment by %s in <%s|%s>" sender.login comment.html_url a)
132
138
in
133
- {
134
- channel;
135
- text = Some summary;
136
- attachments =
137
- Some
138
- [
139
- {
140
- empty_attachments with
141
- mrkdwn_in = Some [ " text" ];
142
- color = Some " #ccc" ;
143
- footer = file;
144
- text = Some (mrkdwn_of_markdown comment.body);
145
- };
146
- ];
147
- blocks = None ;
148
- }
139
+ let attachments =
140
+ Some
141
+ [
142
+ {
143
+ empty_attachments with
144
+ mrkdwn_in = Some [ " text" ];
145
+ color = Some " #ccc" ;
146
+ footer = file;
147
+ text = Some (mrkdwn_of_markdown comment.body);
148
+ };
149
+ ]
150
+ in
151
+ match action with
152
+ | Created -> New_message { channel; text = Some summary; attachments; blocks = None }
153
+ | Edited ->
154
+ ( match State. get_comment_map ctx.state repository.url comment.id with
155
+ | Some ({ channel; ts } : post_message_res ) ->
156
+ Update_message { channel; ts; text = Some summary; attachments; blocks = None }
157
+ | None -> invalid_arg (sprintf " could not find comment %d in %s" comment.id repository.url)
158
+ )
159
+ | _ -> invalid_arg " impossible"
149
160
150
161
let generate_issue_notification notification channel =
151
162
let ({ action; sender; issue; repository } : issue_notification ) = notification in
@@ -166,28 +177,29 @@ let generate_issue_notification notification channel =
166
177
sprintf " <%s|[%s]> Issue #%d %s %s by *%s*" repository.url repository.full_name number (pp_link ~url: html_url title)
167
178
action sender.login
168
179
in
169
- {
170
- channel;
171
- text = Some summary;
172
- attachments =
173
- Some
174
- [
175
- {
176
- empty_attachments with
177
- mrkdwn_in = Some [ " text" ];
178
- color = Some " #ccc" ;
179
- text = mrkdwn_of_markdown_opt body;
180
- };
181
- ];
182
- blocks = None ;
183
- }
180
+ New_message
181
+ {
182
+ channel;
183
+ text = Some summary;
184
+ attachments =
185
+ Some
186
+ [
187
+ {
188
+ empty_attachments with
189
+ mrkdwn_in = Some [ " text" ];
190
+ color = Some " #ccc" ;
191
+ text = mrkdwn_of_markdown_opt body;
192
+ };
193
+ ];
194
+ blocks = None ;
195
+ }
184
196
185
- let generate_issue_comment_notification notification channel =
197
+ let generate_issue_comment_notification ( ctx : Context.t ) notification channel =
186
198
let { action; issue; sender; comment; repository } = notification in
187
199
let { number; title; _ } = issue in
188
200
let action_str =
189
201
match action with
190
- | Created -> " commented"
202
+ | Created | Edited -> " commented"
191
203
| _ ->
192
204
invalid_arg
193
205
(sprintf
@@ -199,21 +211,26 @@ let generate_issue_comment_notification notification channel =
199
211
sprintf " <%s|[%s]> *%s* <%s|%s> on #%d %s" repository.url repository.full_name sender.login comment.html_url
200
212
action_str number (pp_link ~url: issue.html_url title)
201
213
in
202
- {
203
- channel;
204
- text = Some summary;
205
- attachments =
206
- Some
207
- [
208
- {
209
- empty_attachments with
210
- mrkdwn_in = Some [ " text" ];
211
- color = Some " #ccc" ;
212
- text = Some (mrkdwn_of_markdown comment.body);
213
- };
214
- ];
215
- blocks = None ;
216
- }
214
+ let attachments =
215
+ Some
216
+ [
217
+ {
218
+ empty_attachments with
219
+ mrkdwn_in = Some [ " text" ];
220
+ color = Some " #ccc" ;
221
+ text = Some (mrkdwn_of_markdown comment.body);
222
+ };
223
+ ]
224
+ in
225
+ match action with
226
+ | Created -> New_message { channel; text = Some summary; attachments; blocks = None }
227
+ | Edited ->
228
+ ( match State. get_comment_map ctx.state repository.url comment.id with
229
+ | Some ({ channel; ts } : post_message_res ) ->
230
+ Update_message { channel; ts; text = Some summary; attachments; blocks = None }
231
+ | None -> invalid_arg (sprintf " could not find comment %d in %s" comment.id repository.url)
232
+ )
233
+ | _ -> invalid_arg " impossible"
217
234
218
235
let git_short_sha_hash hash = String. sub ~pos: 0 ~len: 8 hash
219
236
@@ -271,21 +288,22 @@ let generate_push_notification notification channel =
271
288
sender.login
272
289
in
273
290
let commits = pp_list_with_previews ~pp_item: pp_commit commits in
274
- {
275
- channel;
276
- text = Some title;
277
- attachments =
278
- Some
279
- [
280
- {
281
- empty_attachments with
282
- mrkdwn_in = Some [ " fields" ];
283
- color = Some " #ccc" ;
284
- fields = Some [ { value = String. concat ~sep: " \n " commits; title = None ; short = false } ];
285
- };
286
- ];
287
- blocks = None ;
288
- }
291
+ New_message
292
+ {
293
+ channel;
294
+ text = Some title;
295
+ attachments =
296
+ Some
297
+ [
298
+ {
299
+ empty_attachments with
300
+ mrkdwn_in = Some [ " fields" ];
301
+ color = Some " #ccc" ;
302
+ fields = Some [ { value = String. concat ~sep: " \n " commits; title = None ; short = false } ];
303
+ };
304
+ ];
305
+ blocks = None ;
306
+ }
289
307
290
308
let generate_status_notification (cfg : Config_t.config ) (notification : status_notification ) channel =
291
309
let { commit; state; description; target_url; context; repository; _ } = notification in
@@ -347,11 +365,11 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
347
365
fields = Some [ { title = None ; value = msg; short = false } ];
348
366
}
349
367
in
350
- { channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
368
+ New_message { channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
351
369
352
- let generate_commit_comment_notification api_commit notification channel =
370
+ let generate_commit_comment_notification ( ctx : Context.t ) api_commit notification channel =
353
371
let { commit; _ } = api_commit in
354
- let { sender; comment; repository; _ } = notification in
372
+ let { sender; comment; repository; action; _ } = notification in
355
373
let commit_id =
356
374
match comment.commit_id with
357
375
| None -> invalid_arg " commit id not found"
@@ -376,7 +394,15 @@ let generate_commit_comment_notification api_commit notification channel =
376
394
text = Some (mrkdwn_of_markdown comment.body);
377
395
}
378
396
in
379
- { channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
397
+ match action with
398
+ | Created -> New_message { channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
399
+ | Edited ->
400
+ ( match State. get_comment_map ctx.state repository.url comment.id with
401
+ | Some ({ channel; ts } : post_message_res ) ->
402
+ Update_message { channel; ts; text = Some summary; attachments = Some [ attachment ]; blocks = None }
403
+ | None -> invalid_arg (sprintf " could not find comment %d in %s" comment.id repository.url)
404
+ )
405
+ | _ -> invalid_arg " impossible"
380
406
381
407
let validate_signature ?(version = " v0" ) ?signing_key ~headers body =
382
408
match signing_key with
0 commit comments