Skip to content

Commit

Permalink
Merge pull request #141 from tatchi/improve-buildkite-description
Browse files Browse the repository at this point in the history
make build number in description a link when using buildkite
  • Loading branch information
Khady authored Mar 15, 2024
2 parents 3d16fc3 + d650f55 commit b23c98a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 15 additions & 1 deletion lib/slack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
8 changes: 4 additions & 4 deletions test/slack_payloads.expected
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ will notify #id[[email protected]]
"fallback": null,
"mrkdwn_in": [ "fields", "text" ],
"color": "danger",
"text": "*Description*: Build #2 failed (20 seconds).",
"text": "*Description*: Build <https://buildkite.com/org/pipeline2/builds/2|#​2> failed (20 seconds).",
"fields": [
{
"value": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: master"
Expand All @@ -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 <https://buildkite.com/org/pipeline2/builds/2|#​2> failed (20 seconds).",
"fields": [
{
"value": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: master"
Expand Down Expand Up @@ -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 <https://buildkite.com/org/pipeline2/builds/2|#​2> passed (5 minutes, 19 seconds).",
"fields": [
{
"value": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: develop"
Expand All @@ -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 <https://buildkite.com/org/pipeline2/builds/2|#​2> passed (5 minutes, 19 seconds).",
"fields": [
{
"value": "*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: master"
Expand Down

0 comments on commit b23c98a

Please sign in to comment.