Skip to content

Commit 8e6f4ef

Browse files
committed
slack: use text field instead of fallback/pretext for msg summary
The top-level text field renders formatted urls correctly in both notifications and slack app, as opposed to the fallback + pretext combination which is less consistent.
1 parent e2ab985 commit 8e6f4ef

File tree

1 file changed

+23
-52
lines changed

1 file changed

+23
-52
lines changed

lib/slack.ml

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,19 @@ let generate_pull_request_notification notification channel =
4949
)
5050
in
5151
let summary =
52-
Some
53-
(sprintf "<%s|[%s]> Pull request #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title
54-
action sender.login
55-
)
52+
sprintf "<%s|[%s]> Pull request #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title
53+
action sender.login
5654
in
5755
{
5856
channel;
59-
text = None;
57+
text = Some summary;
6058
attachments =
6159
Some
6260
[
6361
{
6462
empty_attachments with
6563
mrkdwn_in = Some [ "text" ];
66-
fallback = summary;
6764
color = Some "#ccc";
68-
pretext = summary;
6965
text = mrkdwn_of_markdown_opt body;
7066
};
7167
];
@@ -91,23 +87,19 @@ let generate_pr_review_notification notification channel =
9187
)
9288
in
9389
let summary =
94-
Some
95-
(sprintf "<%s|[%s]> *%s* <%s|%s> #%d <%s|%s>" repository.url repository.full_name sender.login review.html_url
96-
action_str number html_url title
97-
)
90+
sprintf "<%s|[%s]> *%s* <%s|%s> #%d <%s|%s>" repository.url repository.full_name sender.login review.html_url
91+
action_str number html_url title
9892
in
9993
{
10094
channel;
101-
text = None;
95+
text = Some summary;
10296
attachments =
10397
Some
10498
[
10599
{
106100
empty_attachments with
107101
mrkdwn_in = Some [ "text" ];
108-
fallback = summary;
109102
color = Some "#ccc";
110-
pretext = summary;
111103
text = mrkdwn_of_markdown_opt review.body;
112104
};
113105
];
@@ -127,10 +119,8 @@ let generate_pr_review_comment_notification notification channel =
127119
)
128120
in
129121
let summary =
130-
Some
131-
(sprintf "<%s|[%s]> *%s* %s on #%d <%s|%s>" repository.url repository.full_name sender.login action_str number
132-
html_url title
133-
)
122+
sprintf "<%s|[%s]> *%s* %s on #%d <%s|%s>" repository.url repository.full_name sender.login action_str number
123+
html_url title
134124
in
135125
let file =
136126
match comment.path with
@@ -139,16 +129,14 @@ let generate_pr_review_comment_notification notification channel =
139129
in
140130
{
141131
channel;
142-
text = None;
132+
text = Some summary;
143133
attachments =
144134
Some
145135
[
146136
{
147137
empty_attachments with
148138
mrkdwn_in = Some [ "text" ];
149-
fallback = summary;
150139
color = Some "#ccc";
151-
pretext = summary;
152140
footer = file;
153141
text = Some (mrkdwn_of_markdown comment.body);
154142
};
@@ -172,23 +160,19 @@ let generate_issue_notification notification channel =
172160
)
173161
in
174162
let summary =
175-
Some
176-
(sprintf "<%s|[%s]> Issue #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title action
177-
sender.login
178-
)
163+
sprintf "<%s|[%s]> Issue #%d <%s|%s> %s by *%s*" repository.url repository.full_name number html_url title action
164+
sender.login
179165
in
180166
{
181167
channel;
182-
text = None;
168+
text = Some summary;
183169
attachments =
184170
Some
185171
[
186172
{
187173
empty_attachments with
188174
mrkdwn_in = Some [ "text" ];
189-
fallback = summary;
190175
color = Some "#ccc";
191-
pretext = summary;
192176
text = mrkdwn_of_markdown_opt body;
193177
};
194178
];
@@ -209,23 +193,19 @@ let generate_issue_comment_notification notification channel =
209193
)
210194
in
211195
let summary =
212-
Some
213-
(sprintf "<%s|[%s]> *%s* <%s|%s> on #%d <%s|%s>" repository.url repository.full_name sender.login comment.html_url
214-
action_str number issue.html_url title
215-
)
196+
sprintf "<%s|[%s]> *%s* <%s|%s> on #%d <%s|%s>" repository.url repository.full_name sender.login comment.html_url
197+
action_str number issue.html_url title
216198
in
217199
{
218200
channel;
219-
text = None;
201+
text = Some summary;
220202
attachments =
221203
Some
222204
[
223205
{
224206
empty_attachments with
225207
mrkdwn_in = Some [ "text" ];
226-
fallback = summary;
227208
color = Some "#ccc";
228-
pretext = summary;
229209
text = Some (mrkdwn_of_markdown comment.body);
230210
};
231211
];
@@ -283,7 +263,6 @@ let generate_push_notification notification channel =
283263
{
284264
empty_attachments with
285265
mrkdwn_in = Some [ "fields" ];
286-
fallback = Some "Commit pushed notification";
287266
color = Some "#ccc";
288267
fields = Some [ { value = String.concat ~sep:"\n" commits; title = None; short = false } ];
289268
};
@@ -335,27 +314,23 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
335314
let summary =
336315
match target_url with
337316
| None ->
338-
Some (sprintf "<%s|[%s]> CI Build Status notification: %s" repository.url repository.full_name state_info)
317+
sprintf "<%s|[%s]> CI Build Status notification: %s" repository.url repository.full_name state_info
339318
(* in case the CI run is not using buildkite *)
340-
| Some t ->
341-
Some
342-
(sprintf "<%s|[%s]> CI Build Status notification for <%s|%s>: %s" repository.url repository.full_name t context
343-
state_info
344-
)
319+
| Some target_url ->
320+
sprintf "<%s|[%s]> CI Build Status notification for <%s|%s>: %s" repository.url repository.full_name target_url
321+
context state_info
345322
in
346323
let msg = String.concat ~sep:"\n" @@ List.concat [ commit_info; branches_info ] in
347324
let attachment =
348325
{
349326
empty_attachments with
350327
mrkdwn_in = Some [ "fields"; "text" ];
351-
fallback = summary;
352-
pretext = summary;
353328
color = Some color_info;
354329
text = description_info;
355330
fields = Some [ { title = None; value = msg; short = false } ];
356331
}
357332
in
358-
{ channel; text = None; attachments = Some [ attachment ]; blocks = None }
333+
{ channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
359334

360335
let generate_commit_comment_notification api_commit notification channel =
361336
let { commit; _ } = api_commit in
@@ -366,10 +341,8 @@ let generate_commit_comment_notification api_commit notification channel =
366341
| Some c -> c
367342
in
368343
let summary =
369-
Some
370-
(sprintf "<%s|[%s]> *%s* commented on `<%s|%s>` %s" repository.url repository.full_name sender.login
371-
comment.html_url (git_short_sha_hash commit_id) (first_line commit.message)
372-
)
344+
sprintf "<%s|[%s]> *%s* commented on `<%s|%s>` %s" repository.url repository.full_name sender.login comment.html_url
345+
(git_short_sha_hash commit_id) (first_line commit.message)
373346
in
374347
let path =
375348
match comment.path with
@@ -380,14 +353,12 @@ let generate_commit_comment_notification api_commit notification channel =
380353
{
381354
empty_attachments with
382355
mrkdwn_in = Some [ "pretext"; "text" ];
383-
fallback = summary;
384356
color = Some "#ccc";
385-
pretext = summary;
386357
footer = path;
387358
text = Some (mrkdwn_of_markdown comment.body);
388359
}
389360
in
390-
{ channel; text = None; attachments = Some [ attachment ]; blocks = None }
361+
{ channel; text = Some summary; attachments = Some [ attachment ]; blocks = None }
391362

392363
let validate_signature ?(version = "v0") ?signing_key ~headers body =
393364
match signing_key with

0 commit comments

Comments
 (0)