Skip to content

Commit bc47539

Browse files
committed
fix bug in pluralization of “branches” in slack message body
1 parent ef09a4c commit bc47539

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/slack.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,16 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
292292
let branches_info =
293293
match List.map ~f:(fun { name } -> name) notification.branches with
294294
| [] -> [] (* happens when branch is force-pushed by the time CI notification arrives *)
295-
| branches ->
296-
match cfg.main_branch_name with
297-
| Some main when List.mem branches main ~equal:String.equal ->
298-
(* happens when new branches are branched before CI finishes *)
299-
[ sprintf "*Branch*: %s" main ]
300-
| _ -> [ sprintf "*Branches*: %s" (String.concat ~sep:", " branches) ]
295+
| notification_branches ->
296+
let branches =
297+
match cfg.main_branch_name with
298+
| Some main when List.mem notification_branches main ~equal:String.equal ->
299+
(* happens when new branches are branched before CI finishes *)
300+
[ main ]
301+
| _ -> notification_branches
302+
in
303+
let pluralize s = if Int.equal (List.length branches) 1 then s else sprintf "%ses" s in
304+
[ sprintf "*%s*: %s" (pluralize "Branch") (String.concat ~sep:", " branches) ]
301305
in
302306
let summary =
303307
match target_url with

test/slack_payloads.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ will notify #default
477477
"fields": [
478478
{
479479
"value":
480-
"*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branches*: master"
480+
"*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: master"
481481
}
482482
]
483483
}
@@ -543,7 +543,7 @@ will notify #default
543543
"fields": [
544544
{
545545
"value":
546-
"*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branches*: master"
546+
"*Commit*: `<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - Khady\n*Branch*: master"
547547
}
548548
]
549549
}

0 commit comments

Comments
 (0)