Skip to content

Commit 5d070a4

Browse files
committed
slack_msg: unfurling commits always have timestamps in footer
1 parent a1e4119 commit 5d070a4

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

lib/slack.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
open Printf
22
open Base
33
open Common
4+
open Mrkdwn
45
open Github_j
56
open Slack_j
67

@@ -217,9 +218,18 @@ let generate_issue_comment_notification notification channel =
217218
let git_short_sha_hash hash = String.sub ~pos:0 ~len:8 hash
218219

219220
(** pretty print github commit *)
220-
let pp_commit ({ url; id; message; author; _ } : commit) =
221+
let pp_commit_common url id message author =
221222
let title = first_line message in
222-
sprintf "`<%s|%s>` %s - %s" url (git_short_sha_hash id) title author.name
223+
sprintf "`<%s|%s>` %s - %s" url (git_short_sha_hash id) (escape_mrkdwn @@ title) author
224+
225+
let pp_commit ({ url; id; message; author; _ } : commit) = pp_commit_common url id message (escape_mrkdwn @@ author.name)
226+
227+
let pp_api_commit ({ sha; commit; url; author; _ } : api_commit) =
228+
match author with
229+
| Some author ->
230+
pp_commit_common url sha commit.message
231+
(sprintf "<%s|%s>" (escape_mrkdwn author.html_url) (escape_mrkdwn commit.author.name))
232+
| None -> pp_commit_common url sha commit.message commit.author.name
223233

224234
(** pretty print list with previews of each item per line--will always show at most 7 and drop the rest*)
225235
let pp_list_with_previews ~pp_item list =

lib/slack_message.ml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ open Base
22
open Printf
33
open Github_t
44
open Slack_t
5-
open Common
65
open Mrkdwn
76

87
let color_of_state ?(draft = false) ?(merged = false) state =
@@ -146,19 +145,9 @@ let condense_file_changes files =
146145
sprintf "modified %d files%s" (List.length files)
147146
(if String.is_empty prefix_path then "" else sprintf " in `%s/`" prefix_path)
148147

149-
let populate_commit ?(include_changes = true) repository (commit : api_commit) =
150-
let ({ sha; commit; url; author; files; _ } : api_commit) = commit in
151-
let title =
152-
match author with
153-
| Some author ->
154-
sprintf "`<%s|%s>` %s - <%s|%s>" url (Slack.git_short_sha_hash sha)
155-
(escape_mrkdwn @@ first_line commit.message)
156-
(escape_mrkdwn author.html_url) (escape_mrkdwn commit.author.name)
157-
| None ->
158-
sprintf "`<%s|%s>` %s - %s" url (Slack.git_short_sha_hash sha)
159-
(escape_mrkdwn @@ first_line commit.message)
160-
(escape_mrkdwn commit.author.name)
161-
in
148+
let populate_commit ?(include_changes = true) repository (api_commit : api_commit) =
149+
let ({ sha; commit; author; files; _ } : api_commit) = api_commit in
150+
let title = Slack.pp_api_commit api_commit in
162151
let changes () =
163152
let where = condense_file_changes files in
164153
let when_ =
@@ -190,11 +179,7 @@ let populate_commit ?(include_changes = true) repository (commit : api_commit) =
190179
let fallback = sprintf "[%s] %s - %s" (Slack.git_short_sha_hash sha) commit.message commit.author.name in
191180
{
192181
(base_attachment repository) with
193-
footer =
194-
Some
195-
(simple_footer repository
196-
^ if String.equal commit.committer.date commit.author.date then "" else " " ^ commit.committer.date
197-
);
182+
footer = Some (simple_footer repository ^ commit.committer.date);
198183
(*
199184
author_name = Some author.login;
200185
author_link = Some author.html_url;

test/slack_payloads.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ will unfurl in #C047QTRD1CH
587587
"color": "#f6f8fa",
588588
"author_icon": "https://github.com/avatars/u/0",
589589
"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",
590-
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>"
590+
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>2020-06-02T03:14:51Z"
591591
}
592592
}
593593
}

0 commit comments

Comments
 (0)