diff --git a/lib/slack.ml b/lib/slack.ml index 644ee0f6..1a2b0f11 100644 --- a/lib/slack.ml +++ b/lib/slack.ml @@ -246,7 +246,21 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_ let description_info = match description with | None -> None - | Some s -> Some (sprintf "*Description*: %s." s) + | Some s -> + let text = + match target_url with + | None -> s + | Some target_url -> + (* Specific to buildkite *) + let re = Re2.create_exn {|^Build #(\d+)(.*)|} in + ( match Re2.find_submatches_exn re s with + | [| Some _; Some build_nr; Some rest |] -> + (* We use a zero-with space \u{200B} to prevent slack from interpreting #XXXXXX as a color *) + sprintf "Build <%s|#\u{200B}%s>%s" target_url build_nr rest + | _ -> s + ) + in + Some (sprintf "*Description*: %s." text) in let commit_info = [ sprintf "*Commit*: `<%s|%s>` %s - %s" html_url (git_short_sha_hash sha) (first_line message) author.login ] diff --git a/test/slack_payloads.expected b/test/slack_payloads.expected index 5e1e2672..a25684ec 100644 --- a/test/slack_payloads.expected +++ b/test/slack_payloads.expected @@ -440,7 +440,7 @@ will notify #id[slack_mail@example.com] "fallback": null, "mrkdwn_in": [ "fields", "text" ], "color": "danger", - "text": "*Description*: Build #2 failed (20 seconds).", + "text": "*Description*: Build failed (20 seconds).", "fields": [ { "value": "*Commit*: `` Update README.md - Khady\n*Branch*: master" @@ -459,7 +459,7 @@ will notify #default "fallback": null, "mrkdwn_in": [ "fields", "text" ], "color": "danger", - "text": "*Description*: Build #2 failed (20 seconds).", + "text": "*Description*: Build failed (20 seconds).", "fields": [ { "value": "*Commit*: `` Update README.md - Khady\n*Branch*: master" @@ -502,7 +502,7 @@ will notify #all-push-events "fallback": null, "mrkdwn_in": [ "fields", "text" ], "color": "good", - "text": "*Description*: Build #2 passed (5 minutes, 19 seconds).", + "text": "*Description*: Build passed (5 minutes, 19 seconds).", "fields": [ { "value": "*Commit*: `` Update README.md - Khady\n*Branch*: develop" @@ -522,7 +522,7 @@ will notify #default "fallback": null, "mrkdwn_in": [ "fields", "text" ], "color": "good", - "text": "*Description*: Build #2 passed (5 minutes, 19 seconds).", + "text": "*Description*: Build passed (5 minutes, 19 seconds).", "fields": [ { "value": "*Commit*: `` Update README.md - Khady\n*Branch*: master"