Skip to content

Commit a511882

Browse files
EmileTrotignonEmile Trotignonthatportugueseguy
authored
10 lines of failure log are disaplayed in the error DMmessage (#194)
* 10 lines of failure log are disaplayed in the message * put the log in an attachment * Update lib/slack.ml Co-authored-by: José Nogueira <[email protected]> * Update lib/slack.ml Co-authored-by: José Nogueira <[email protected]> * cleanup --------- Co-authored-by: Emile Trotignon <[email protected]> Co-authored-by: José Nogueira <[email protected]>
1 parent e229fb4 commit a511882

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

lib/slack.ml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,21 @@ let generate_status_notification ~(job_log : (string * string) list) ~(cfg : Con
380380
in
381381
[ sprintf "*%s*: %s" (pluralize ~suf:"es" ~len:(List.length branches) "Branch") (String.concat ", " branches) ]
382382
in
383+
let job_log_lines ~n =
384+
job_log
385+
|> List.map (fun (job_name, job_log) ->
386+
let lines = job_log |> Text_cleanup.cleanup |> String.split_on_char '\n' |> List.rev |> List.to_seq in
387+
let text = lines |> Seq.take n |> List.of_seq |> List.rev |> String.concat "\n" in
388+
(* Buildkite has different "sections" on their builds logs. The commands we run come only after this line. *)
389+
let after_cmd = Stre.after text "~~~ Running commands\n" |> String.trim in
390+
let text = if after_cmd <> "" then after_cmd else text in
391+
job_name, text)
392+
in
393+
let fields =
394+
job_log_lines ~n:10 |> function
395+
| [] -> None
396+
| (job_log, content) :: _ -> Some [ { title = Some job_log; value = sprintf "```%s```" content; short = false } ]
397+
in
383398
let summary =
384399
let state_info =
385400
match state with
@@ -413,7 +428,9 @@ let generate_status_notification ~(job_log : (string * string) list) ~(cfg : Con
413428
| Some pipeline_url -> sprintf "<%s|[%s]>: %s for \"%s\"" pipeline_url context build_desc commit_message)
414429
in
415430
let text = Some (String.concat "\n" @@ List.concat [ commit_info; branches_info ]) in
416-
let attachment = { empty_attachments with mrkdwn_in = Some [ "fields"; "text" ]; color = Some color_info; text } in
431+
let attachment =
432+
{ empty_attachments with mrkdwn_in = Some [ "fields"; "text" ]; color = Some color_info; text; fields }
433+
in
417434
let handler =
418435
match job_log with
419436
| [] ->
@@ -422,24 +439,9 @@ let generate_status_notification ~(job_log : (string * string) list) ~(cfg : Con
422439
| _ :: _ when Status_notification.is_user channel ->
423440
log#info "failed jobs logs are going to be sent";
424441
let files =
425-
job_log
426-
|> List.map (fun (job_name, job_log) ->
427-
let clean =
428-
job_log
429-
|> Text_cleanup.cleanup
430-
|> String.split_on_char '\n'
431-
|> List.rev
432-
|> List.to_seq
433-
|> Seq.take 200
434-
|> List.of_seq
435-
|> List.rev
436-
|> String.concat "\n"
437-
in
438-
(* Buildkite has different "sections" on their builds logs. The commands we run come only after this line. *)
439-
let content = Stre.after clean "~~~ Running commands\n" |> String.trim in
440-
let content = if content <> "" then content else clean in
441-
{ name = job_name; title = None; alt_txt = None; content })
442+
job_log_lines ~n:100 |> List.map (fun (name, content) -> { name; title = None; alt_txt = None; content })
442443
in
444+
443445
Some
444446
(fun (send_file : file:file_req -> (unit, string) result Lwt.t) (res : Slack_t.post_message_res) ->
445447
let ({ ts; channel; _ } : post_message_res) = res in

test/slack_payloads.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ will notify #default
547547
"fallback": null,
548548
"mrkdwn_in": [ "fields", "text" ],
549549
"color": "danger",
550-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage"
550+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage\n*Test on buildkite-agent-1.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
551551
}
552552
],
553553
"unfurl_links": false
@@ -561,7 +561,7 @@ will notify #id[[email protected]]
561561
"fallback": null,
562562
"mrkdwn_in": [ "fields", "text" ],
563563
"color": "danger",
564-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage"
564+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage\n*Test on buildkite-agent-1.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
565565
}
566566
],
567567
"unfurl_links": false
@@ -596,7 +596,7 @@ will notify #default
596596
"fallback": null,
597597
"mrkdwn_in": [ "fields", "text" ],
598598
"color": "danger",
599-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage"
599+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage\n*Test on buildkite-agent-1.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
600600
}
601601
],
602602
"unfurl_links": false
@@ -611,7 +611,7 @@ will notify #default
611611
"fallback": null,
612612
"mrkdwn_in": [ "fields", "text" ],
613613
"color": "danger",
614-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage"
614+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
615615
}
616616
],
617617
"unfurl_links": false
@@ -626,7 +626,7 @@ will notify #all-push-events
626626
"fallback": null,
627627
"mrkdwn_in": [ "fields", "text" ],
628628
"color": "danger",
629-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop"
629+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop\n*Test on buildkite-agent-1.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
630630
}
631631
],
632632
"unfurl_links": false
@@ -641,7 +641,7 @@ will notify #default
641641
"fallback": null,
642642
"mrkdwn_in": [ "fields", "text" ],
643643
"color": "danger",
644-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage"
644+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: author/patches/js-storage\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
645645
}
646646
],
647647
"unfurl_links": false
@@ -656,7 +656,7 @@ will notify #all-push-events
656656
"fallback": null,
657657
"mrkdwn_in": [ "fields", "text" ],
658658
"color": "danger",
659-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop"
659+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
660660
}
661661
],
662662
"unfurl_links": false
@@ -671,7 +671,7 @@ will notify #all-push-events
671671
"fallback": null,
672672
"mrkdwn_in": [ "fields", "text" ],
673673
"color": "danger",
674-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop"
674+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
675675
}
676676
],
677677
"unfurl_links": false
@@ -701,7 +701,7 @@ will notify #all-push-events
701701
"fallback": null,
702702
"mrkdwn_in": [ "fields", "text" ],
703703
"color": "danger",
704-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop"
704+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b|7e0a933e>` author\n*Branch*: develop\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
705705
}
706706
],
707707
"unfurl_links": false
@@ -716,7 +716,7 @@ will notify #default
716716
"fallback": null,
717717
"mrkdwn_in": [ "fields", "text" ],
718718
"color": "danger",
719-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: master"
719+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: master\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
720720
}
721721
],
722722
"unfurl_links": false
@@ -731,7 +731,7 @@ will notify #all-push-events
731731
"fallback": null,
732732
"mrkdwn_in": [ "fields", "text" ],
733733
"color": "danger",
734-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: develop"
734+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: develop\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
735735
}
736736
],
737737
"unfurl_links": false
@@ -746,7 +746,7 @@ will notify #default
746746
"fallback": null,
747747
"mrkdwn_in": [ "fields", "text" ],
748748
"color": "danger",
749-
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: master"
749+
"text": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Khady\n*Branch*: master\n*Test on unknown.txt*\n```diff --git a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\nindex 88404ca..a9e2880 100644\n--- a/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t\n+++ b/_build/.sandbox/ca5ef14ba31cbcd6e129c4c5b8cdc872/default/tests/test.t.corrected\n@@ -1,2 +1,2 @@\n $ dune exec backend\n- aaabvaaa\n+ aaaa\n🚨 Error: The command exited with status 1\n```"
750750
}
751751
],
752752
"unfurl_links": false

0 commit comments

Comments
 (0)