Skip to content

Commit 28cd213

Browse files
committed
slack: don't link to compare for 1-commit push
1 parent 4eb47a0 commit 28cd213

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/slack.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ let generate_push_notification notification channel =
230230
let commits_branch = Github.commits_branch_of_ref notification.ref in
231231
let tree_url = String.concat ~sep:"/" [ repository.url; "tree"; Uri.pct_encode commits_branch ] in
232232
let num_commits = List.length commits in
233+
let compare =
234+
(* if single commit, don't show compare *)
235+
match commits with
236+
| [ { url; _ } ] -> url
237+
| _ -> compare
238+
in
233239
let title =
234240
if deleted then
235241
sprintf "<%s|[%s]> %s deleted branch <%s|%s>" tree_url repository.name sender.login compare commits_branch

test/slack_payloads.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ will notify #backend1
455455
{
456456
"channel": "backend1",
457457
"text":
458-
"<https://github.com/octocat/test-repo/tree/develop|[test-repo:develop]> <https://github.com/octocat/test-repo/compare/fb245e2a6d52...e2173f38ae43|1 commit> pushed by octocat",
458+
"<https://github.com/octocat/test-repo/tree/develop|[test-repo:develop]> <https://github.com/octocat/test-repo/commit/80452f696a8988e7234063d47720a62e902f2afc|1 commit> pushed by octocat",
459459
"attachments": [
460460
{
461461
"fallback": "Commit pushed notification",
@@ -475,7 +475,7 @@ will notify #backend1
475475
{
476476
"channel": "backend1",
477477
"text":
478-
"<https://github.com/octocat/test-repo/tree/master|[test-repo:master]> <https://github.com/octocat/test-repo/compare/fb245e2a6d52...e2173f38ae43|1 commit> pushed by octocat",
478+
"<https://github.com/octocat/test-repo/tree/master|[test-repo:master]> <https://github.com/octocat/test-repo/commit/80452f696a8988e7234063d47720a62e902f2afc|1 commit> pushed by octocat",
479479
"attachments": [
480480
{
481481
"fallback": "Commit pushed notification",
@@ -514,7 +514,7 @@ will notify #default
514514
{
515515
"channel": "default",
516516
"text":
517-
"<https://github.com/octocat/test-repo/tree/feature%2Ff1|[test-repo:feature/f1]> <https://github.com/octocat/test-repo/compare/fb245e2a6d52...e2173f38ae43|1 commit> pushed by octocat",
517+
"<https://github.com/octocat/test-repo/tree/feature%2Ff1|[test-repo:feature/f1]> <https://github.com/octocat/test-repo/commit/80452f696a8988e7234063d47720a62e902f2afc|1 commit> pushed by octocat",
518518
"attachments": [
519519
{
520520
"fallback": "Commit pushed notification",
@@ -573,7 +573,7 @@ will notify #longest-a1
573573
{
574574
"channel": "longest-a1",
575575
"text":
576-
"<https://github.com/thatportugueseguy/monorepo/tree/develop|[monorepo:develop]> <https://github.com/thatportugueseguy/monorepo/compare/fb245e2a6d52...e2173f38ae43|1 commit> pushed by thatportugueseguy",
576+
"<https://github.com/thatportugueseguy/monorepo/tree/develop|[monorepo:develop]> <https://github.com/thatportugueseguy/monorepo/commit/e2173f38ae43865433a182c1fc1b5442d9763b54|1 commit> pushed by thatportugueseguy",
577577
"attachments": [
578578
{
579579
"fallback": "Commit pushed notification",

0 commit comments

Comments
 (0)