@@ -216,6 +216,25 @@ let generate_issue_comment_notification notification channel =
216
216
217
217
let git_short_sha_hash hash = String. sub ~pos: 0 ~len: 8 hash
218
218
219
+ (* * pretty print github commit *)
220
+ let pp_commit ({ url; id; message; author; _ } : commit ) =
221
+ let title = first_line message in
222
+ sprintf " `<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name
223
+
224
+ (* * pretty print list with previews of each item per line--will always show at most 7 and drop the rest*)
225
+ let pp_list_with_previews ~pp_item list =
226
+ let num_items = List. length list in
227
+ (* truncation point depends on line length, but 7+3 lines seems okay for most cases *)
228
+ let num_shown = 7 in
229
+ let dropped = num_items - num_shown in
230
+ if dropped > 3 then begin
231
+ let h, list ' = List. split_n list (num_shown / 2 ) in
232
+ let t = List. drop list ' dropped in
233
+ let num_after_h = num_items - List. length h in
234
+ List. concat [ List. map ~f: pp_item h; [ sprintf " +%d more...\n " num_after_h ]; List. map ~f: pp_item t ]
235
+ end
236
+ else List. map ~f: pp_item list
237
+
219
238
let generate_push_notification notification channel =
220
239
let { sender; created; deleted; forced; compare; commits; repository; _ } = notification in
221
240
let commits_branch = Github. commits_branch_of_ref notification.ref in
@@ -241,21 +260,7 @@ let generate_push_notification notification channel =
241
260
(if created then " to new branch " else " " )
242
261
sender.login
243
262
in
244
- let commits =
245
- let pp_commit { url; id; message; author; _ } =
246
- let title = first_line message in
247
- sprintf " `<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name
248
- in
249
- (* truncation point depends on line length, but 7+3 lines seems okay for most cases *)
250
- let num_shown = 7 in
251
- let dropped = num_commits - num_shown in
252
- if dropped > 3 then begin
253
- let h, commits' = List. split_n commits (num_shown / 2 ) in
254
- let t = List. drop commits' dropped in
255
- List. concat [ List. map ~f: pp_commit h; [ sprintf " +%d more..." dropped ]; List. map ~f: pp_commit t ]
256
- end
257
- else List. map commits ~f: pp_commit
258
- in
263
+ let commits = pp_list_with_previews ~pp_item: pp_commit commits in
259
264
{
260
265
channel;
261
266
text = Some title;
0 commit comments