Skip to content

Commit 723711b

Browse files
committed
show number of changed files in longest shared prefix
1 parent c078c41 commit 723711b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/common.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ let write_to_local_file ~data path =
3636
try Ok (Devkit.Files.save_as path (fun oc -> Stdio.Out_channel.fprintf oc "%s" data))
3737
with exn -> fmt_error "%s" (Exn.to_string exn)
3838

39+
let longest_common_prefix xs =
40+
match xs with
41+
| [] -> ""
42+
| [ x ] -> x
43+
| x :: _ -> String.sub x ~pos:0 ~len:(Stre.common_prefix x (List.sort xs ~compare:String.compare |> List.last_exn))
44+
3945
let sign_string_sha256 ~key ~basestring =
4046
Cstruct.of_string basestring |> Nocrypto.Hash.SHA256.hmac ~key:(Cstruct.of_string key) |> Hex.of_cstruct |> Hex.show

lib/slack_message.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,24 @@ let empty_attachment =
2727
let base_attachment (repository : repository) =
2828
{ empty_attachment with footer = Some (sprintf "<%s|%s>" repository.url (escape_mrkdwn repository.full_name)) }
2929

30-
let pp_file (file : file) = sprintf "<%s|%s>" file.url (Mrkdwn.escape_mrkdwn file.filename)
31-
3230
let populate_commit repository (commit : api_commit) =
33-
let ({ sha; commit; url; author; files; stats } : api_commit) = commit in
34-
let get_files () = List.map files ~f:pp_file in
31+
let ({ sha; commit; url; author; files; _ } : api_commit) = commit in
3532
let title =
3633
sprintf "`<%s|%s>` *%s - %s*" url (Slack.git_short_sha_hash sha)
3734
(escape_mrkdwn @@ first_line commit.message)
3835
(escape_mrkdwn commit.author.name)
3936
in
4037
let num_change = List.length files in
41-
let changes =
42-
sprintf "%d %s with %d %s and %d %s:" num_change
43-
(Slack.pluralize "changed file" num_change "s")
44-
stats.additions
45-
(Slack.pluralize "addition" stats.additions "s")
46-
stats.deletions
47-
(Slack.pluralize "deletion" stats.deletions "s")
38+
let prefix_path =
39+
List.map files ~f:(fun f -> f.filename)
40+
|> Common.longest_common_prefix
41+
|> String.split ~on:'/'
42+
|> List.drop_last_exn
43+
|> String.concat ~sep:"/"
4844
in
49-
let files = get_files () |> String.concat ~sep:"\n" in
50-
let text = sprintf "%s\n%s\n%s" title changes files in
51-
let fallback = sprintf "[%s] %s - %s" (git_short_sha_hash sha) commit.message commit.author.name in
45+
let changes = sprintf "%d changed %s in `%s/`" num_change (Slack.pluralize "file" num_change "s") prefix_path in
46+
let text = sprintf "%s\n%s" title changes in
47+
let fallback = sprintf "[%s] %s - %s" (Slack.git_short_sha_hash sha) commit.message commit.author.name in
5248
{
5349
(base_attachment repository) with
5450
author_name = Some author.login;

0 commit comments

Comments
 (0)