Skip to content

Commit 098411e

Browse files
committed
use plaintext for all fallback messages
1 parent e4932da commit 098411e

File tree

2 files changed

+83
-52
lines changed

2 files changed

+83
-52
lines changed

lib/slack.ml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ let generate_pull_request_notification notification channel =
5353
(sprintf "<%s|[%s]> Pull request #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title
5454
action sender.login)
5555
in
56+
let fallback =
57+
Some (sprintf "[%s] Pull request #%d %s %s by %s" repository.full_name number title action sender.login)
58+
in
5659
{
5760
channel;
5861
text = None;
@@ -62,7 +65,7 @@ let generate_pull_request_notification notification channel =
6265
{
6366
empty_attachments with
6467
mrkdwn_in = Some [ "text" ];
65-
fallback = summary;
68+
fallback;
6669
color = Some "#ccc";
6770
pretext = summary;
6871
text = mrkdwn_of_markdown_opt body;
@@ -93,6 +96,7 @@ let generate_pr_review_notification notification channel =
9396
(sprintf "<%s|[%s]> *%s* <%s|%s> #%d <%s|%s>" repository.url repository.full_name sender.login review.html_url
9497
action_str number html_url title)
9598
in
99+
let fallback = Some (sprintf "[%s] %s %s #%d %s" repository.full_name sender.login action_str number title) in
96100
{
97101
channel;
98102
text = None;
@@ -102,7 +106,7 @@ let generate_pr_review_notification notification channel =
102106
{
103107
empty_attachments with
104108
mrkdwn_in = Some [ "text" ];
105-
fallback = summary;
109+
fallback;
106110
color = Some "#ccc";
107111
pretext = summary;
108112
text = mrkdwn_of_markdown_opt review.body;
@@ -127,6 +131,7 @@ let generate_pr_review_comment_notification notification channel =
127131
(sprintf "<%s|[%s]> *%s* %s on #%d <%s|%s>" repository.url repository.full_name sender.login action_str number
128132
html_url title)
129133
in
134+
let fallback = Some (sprintf "[%s] %s %s on #%d %s" repository.full_name sender.login action_str number title) in
130135
let file =
131136
match comment.path with
132137
| None -> None
@@ -141,7 +146,7 @@ let generate_pr_review_comment_notification notification channel =
141146
{
142147
empty_attachments with
143148
mrkdwn_in = Some [ "text" ];
144-
fallback = summary;
149+
fallback;
145150
color = Some "#ccc";
146151
pretext = summary;
147152
footer = file;
@@ -170,6 +175,7 @@ let generate_issue_notification notification channel =
170175
(sprintf "<%s|[%s]> Issue #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title action
171176
sender.login)
172177
in
178+
let fallback = Some (sprintf "[%s] Issue #%d %s %s by %s" repository.full_name number title action sender.login) in
173179
{
174180
channel;
175181
text = None;
@@ -179,7 +185,7 @@ let generate_issue_notification notification channel =
179185
{
180186
empty_attachments with
181187
mrkdwn_in = Some [ "text" ];
182-
fallback = summary;
188+
fallback;
183189
color = Some "#ccc";
184190
pretext = summary;
185191
text = mrkdwn_of_markdown_opt body;
@@ -205,6 +211,7 @@ let generate_issue_comment_notification notification channel =
205211
(sprintf "<%s|[%s]> *%s* <%s|%s> on #%d <%s|%s>" repository.url repository.full_name sender.login comment.html_url
206212
action_str number issue.html_url title)
207213
in
214+
let fallback = Some (sprintf "[%s] %s %s on #%d %s" repository.full_name sender.login action_str number title) in
208215
{
209216
channel;
210217
text = None;
@@ -214,7 +221,7 @@ let generate_issue_comment_notification notification channel =
214221
{
215222
empty_attachments with
216223
mrkdwn_in = Some [ "text" ];
217-
fallback = summary;
224+
fallback;
218225
color = Some "#ccc";
219226
pretext = summary;
220227
text = Some (mrkdwn_of_markdown comment.body);
@@ -243,21 +250,34 @@ let generate_push_notification notification channel =
243250
(if created then "to new branch " else "")
244251
sender.login
245252
in
253+
let fallback =
254+
if deleted then sprintf "[%s] %s deleted branch %s" repository.name sender.login commits_branch
255+
else
256+
sprintf "[%s:%s] %i commit%s %spushed %sby %s" repository.name commits_branch (List.length commits)
257+
( match commits with
258+
| [ _ ] -> ""
259+
| _ -> "s"
260+
)
261+
(if forced then "force-" else "")
262+
(if created then "to new branch " else "")
263+
sender.login
264+
in
246265
let commits =
247266
List.map commits ~f:(fun { url; id; message; author; _ } ->
248267
let title = first_line message in
249268
sprintf "`<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name)
250269
in
251270
{
252271
channel;
253-
text = Some title;
272+
text = None;
254273
attachments =
255274
Some
256275
[
257276
{
258277
empty_attachments with
259278
mrkdwn_in = Some [ "fields" ];
260-
fallback = Some "Commit pushed notification";
279+
pretext = Some title;
280+
fallback = Some fallback;
261281
color = Some "#ccc";
262282
fields = Some [ { value = String.concat ~sep:"\n" commits; title = None; short = false } ];
263283
};
@@ -315,12 +335,19 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
315335
(sprintf "<%s|[%s]> CI Build Status notification for <%s|%s>: %s" repository.url repository.full_name t context
316336
state_info)
317337
in
338+
let fallback =
339+
match target_url with
340+
| None ->
341+
Some (sprintf "[%s] CI Build Status notification: %s" repository.full_name state_info)
342+
(* in case the CI run is not using buildkite *)
343+
| Some _ -> Some (sprintf "[%s] CI Build Status notification for %s: %s" repository.full_name context state_info)
344+
in
318345
let msg = String.concat ~sep:"\n" @@ List.concat [ commit_info; branches_info ] in
319346
let attachment =
320347
{
321348
empty_attachments with
322349
mrkdwn_in = Some [ "fields"; "text" ];
323-
fallback = summary;
350+
fallback;
324351
pretext = summary;
325352
color = Some color_info;
326353
text = description_info;
@@ -342,6 +369,11 @@ let generate_commit_comment_notification api_commit notification channel =
342369
(sprintf "<%s|[%s]> *%s* commented on `<%s|%s>` %s" repository.url repository.full_name sender.login
343370
comment.html_url (git_short_sha_hash commit_id) (first_line commit.message))
344371
in
372+
let fallback =
373+
Some
374+
(sprintf "[%s] %s commented on `%s` %s" repository.full_name sender.login (git_short_sha_hash commit_id)
375+
(first_line commit.message))
376+
in
345377
let path =
346378
match comment.path with
347379
| None -> None
@@ -351,7 +383,7 @@ let generate_commit_comment_notification api_commit notification channel =
351383
{
352384
empty_attachments with
353385
mrkdwn_in = Some [ "pretext"; "text" ];
354-
fallback = summary;
386+
fallback;
355387
color = Some "#ccc";
356388
pretext = summary;
357389
footer = path;

0 commit comments

Comments
 (0)