Skip to content

Commit 3c018d8

Browse files
committed
slack: limit to 10 commits to avoid mid-line msg truncation
1 parent 49f0219 commit 3c018d8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/slack.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ let generate_push_notification notification channel =
229229
let { sender; created; deleted; forced; compare; commits; repository; _ } = notification in
230230
let commits_branch = Github.commits_branch_of_ref notification.ref in
231231
let tree_url = String.concat ~sep:"/" [ repository.url; "tree"; Uri.pct_encode commits_branch ] in
232+
let num_commits = List.length commits in
232233
let title =
233234
if deleted then
234235
sprintf "<%s|[%s]> %s deleted branch <%s|%s>" tree_url repository.name sender.login compare commits_branch
235236
else
236237
sprintf "<%s|[%s:%s]> <%s|%i commit%s> %spushed %sby %s" tree_url repository.name commits_branch compare
237-
(List.length commits)
238+
num_commits
238239
( match commits with
239240
| [ _ ] -> ""
240241
| _ -> "s"
@@ -244,9 +245,16 @@ let generate_push_notification notification channel =
244245
sender.login
245246
in
246247
let commits =
247-
List.map commits ~f:(fun { url; id; message; author; _ } ->
248+
let pp_commit { url; id; message; author; _ } =
248249
let title = first_line message in
249-
sprintf "`<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name)
250+
sprintf "`<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name
251+
in
252+
(* truncation point depends on line length, but 10 lines seems okay for most cases *)
253+
let num_dropped = 10 in
254+
let dropped = num_commits - num_dropped in
255+
if dropped > 0 then
256+
List.rev_map_append (List.drop (List.rev commits) dropped) [ sprintf "+%d more..." dropped ] ~f:pp_commit
257+
else List.map commits ~f:pp_commit
250258
in
251259
{
252260
channel;

0 commit comments

Comments
 (0)