Skip to content

Commit 5bdf24c

Browse files
committed
slack: show date in unfurl
1 parent 722c5c4 commit 5bdf24c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/github.atd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ type git_user = {
66
?username: string option;
77
}
88

9+
type git_user_with_date = {
10+
name: string;
11+
email: string;
12+
date: string;
13+
}
14+
915
type commit_hash = string
1016

1117
type commit = {
@@ -14,7 +20,7 @@ type commit = {
1420
message: string;
1521
timestamp: string;
1622
url: string;
17-
author: git_user;
23+
author: git_user;
1824
committer: git_user;
1925
added: string list;
2026
removed: string list;
@@ -209,7 +215,8 @@ type status_state = [
209215
] <ocaml repr="classic">
210216

211217
type inner_commit = {
212-
author: git_user;
218+
author: git_user_with_date;
219+
committer: git_user_with_date;
213220
message: string;
214221
}
215222

lib/slack_message.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ let empty_attachment =
3737
footer = None;
3838
}
3939

40-
let base_attachment (repository : repository) =
41-
{ empty_attachment with footer = Some (sprintf "<%s|%s>" repository.url (escape_mrkdwn repository.full_name)) }
42-
40+
let simple_footer (repository : repository) = sprintf "<%s|%s>" repository.url (escape_mrkdwn repository.full_name)
41+
let base_attachment repository = { empty_attachment with footer = Some (simple_footer repository) }
4342
let pp_label (label : label) = label.name
44-
4543
let pp_github_user (user : github_user) = gh_name_of_string user.login
46-
4744
let pp_github_team (team : github_team) = gh_name_of_string team.slug
4845

4946
let populate_pull_request repository (pull_request : pull_request) =
@@ -137,12 +134,20 @@ let populate_commit repository (commit : api_commit) =
137134
|> List.drop_last_exn
138135
|> String.concat ~sep:"/"
139136
in
140-
sprintf "modified %d files in `%s/`" (List.length files) prefix_path
137+
let where = if String.is_empty prefix_path then "" else sprintf " in `%s/`" prefix_path in
138+
(* TODO use "today" on same day, "Month Day" during same year
139+
even better would be to have "N units ago" and tooltip, but looks like slack doesn't provide such thing *)
140+
sprintf "modified %d files%s on %s" (List.length files) where commit.author.date
141141
in
142142
let text = sprintf "%s\n%s" title changes in
143143
let fallback = sprintf "[%s] %s - %s" (Slack.git_short_sha_hash sha) commit.message commit.author.name in
144144
{
145145
(base_attachment repository) with
146+
footer =
147+
Some
148+
(simple_footer repository
149+
^ if String.equal commit.committer.date commit.author.date then "" else " " ^ commit.committer.date
150+
);
146151
(*
147152
author_name = Some author.login;
148153
author_link = Some author.html_url;

0 commit comments

Comments
 (0)