Skip to content

Commit 479ac73

Browse files
committed
slack_message, github: simplify gh_link_re, and fixed condense files modified notification
1 parent 98404d1 commit 479ac73

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/github.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type gh_link =
9595
| Commit of repository * commit_hash
9696
| Compare of repository * basehead
9797

98-
let gh_link_re = Re2.create_exn {|^(.*)/(.+)/(.+)/(commit|pull|issues|compare)/([a-zA-Z0-9/:\-_.~\^]+)/?$|}
98+
let gh_link_re = Re2.create_exn {|^(.*)/(.+)/(.+)/(commit|pull|issues|compare)/([a-zA-Z0-9/:\-_.~\^]+)$|}
9999
let commit_sha_re = Re2.create_exn {|[a-f0-9]{4,40}|}
100100
let comparer_re = {|([a-zA-Z0-9/:\-_.~\^]+)|}
101101
let compare_basehead_re = Re2.create_exn (sprintf {|%s([.]{3})%s|} comparer_re comparer_re)

lib/slack_message.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ let condense_file_changes files =
143143
|> List.drop_last_exn
144144
|> String.concat ~sep:"/"
145145
in
146-
if String.is_empty prefix_path then "" else sprintf " in `%s/`" prefix_path
146+
if String.is_empty prefix_path then "" else sprintf "modified %d files in `%s/`" (List.length files) prefix_path
147147

148148
let populate_commit ?(include_changes = true) repository (commit : api_commit) =
149149
let ({ sha; commit; url; author; files; _ } : api_commit) = commit in
@@ -175,19 +175,17 @@ let populate_commit ?(include_changes = true) repository (commit : api_commit) =
175175
in
176176
( match List.map ~f:Int.of_string @@ String.split date ~on:'-' with
177177
| [ y; m; d ] when y = yy && m = mm && d = dd -> "today"
178-
| [ y; m; d ] when y = yy -> sprintf " on %s %d" (month m) d
179-
| _ -> date
178+
| [ y; m; d ] when y = yy -> sprintf "on %s %d" (month m) d
179+
| _ -> "on " ^ date
180180
)
181181
| _ -> failwith "wut"
182-
with _ -> " on " ^ commit.author.date
182+
with _ -> "on " ^ commit.author.date
183183
in
184-
sprintf "modified %d files%s %s" (List.length files) where when_
185-
in
186-
let text =
187-
match include_changes with
188-
| false -> sprintf "%s\n" title
189-
| true -> sprintf "%s\n%s" title (changes ())
184+
match where, when_ with
185+
| "", when_ -> when_
186+
| where, when_ -> sprintf "%s %s" where when_
190187
in
188+
let text = sprintf "%s\n%s" title (if include_changes then changes () else "") in
191189
let fallback = sprintf "[%s] %s - %s" (Slack.git_short_sha_hash sha) commit.message commit.author.name in
192190
{
193191
(base_attachment repository) with

test/slack_payloads.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ will unfurl in #C047QTRD1CH
586586
"mrkdwn_in": [ "text" ],
587587
"color": "#f6f8fa",
588588
"author_icon": "https://github.com/avatars/u/0",
589-
"text": "`<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - <https://github.com/Khady|Louis>\nmodified 1 files_modified `README.md` (+1-1)_ 2020-06-02",
589+
"text": "`<https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478|0d95302a>` Update README.md - <https://github.com/Khady|Louis>\n_modified `README.md` (+1-1)_ on 2020-06-02",
590590
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>"
591591
}
592592
}

0 commit comments

Comments
 (0)