@@ -116,6 +116,22 @@ let populate_issue repository (issue : issue) =
116
116
fallback = Some (sprintf " [%s] %s" repository.full_name title);
117
117
}
118
118
119
+ (* use some date library :see_no_evil: *)
120
+ let month = function
121
+ | 1 -> " Jan"
122
+ | 2 -> " Feb"
123
+ | 3 -> " Mar"
124
+ | 4 -> " Apr"
125
+ | 5 -> " May"
126
+ | 6 -> " Jun"
127
+ | 7 -> " Jul"
128
+ | 8 -> " Aug"
129
+ | 9 -> " Sep"
130
+ | 10 -> " Oct"
131
+ | 11 -> " Nov"
132
+ | 12 -> " Dec"
133
+ | _ -> assert false
134
+
119
135
let populate_commit repository (commit : api_commit ) =
120
136
let ({ sha; commit; url; author; files; _ } : api_commit ) = commit in
121
137
let title =
@@ -135,9 +151,28 @@ let populate_commit repository (commit : api_commit) =
135
151
|> String. concat ~sep: " /"
136
152
in
137
153
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
154
+ let when_ =
155
+ (*
156
+ use "today" on same day, "Month Day" during same year
157
+ even better would be to have "N units ago" and tooltip computed by slack at time of presentation
158
+ but looks like slack doesn't provide such functionality
159
+ *)
160
+ try
161
+ match String. split commit.author.date ~on: 'T' with
162
+ | [ date; _ ] ->
163
+ let yy, mm, dd =
164
+ let tm = Unix. gmtime @@ Devkit.Time. now () in
165
+ tm.tm_year + 1900 , tm.tm_mon + 1 , tm.tm_mday
166
+ in
167
+ ( match List. map ~f: Int. of_string @@ String. split date ~on: '-' with
168
+ | [ y; m; d ] when y = yy && m = mm && d = dd -> " today"
169
+ | [ y; m; d ] when y = yy -> sprintf " on %s %d" (month m) d
170
+ | _ -> date
171
+ )
172
+ | _ -> failwith " wut"
173
+ with _ -> " on " ^ commit.author.date
174
+ in
175
+ sprintf " modified %d files%s %s" (List. length files) where when_
141
176
in
142
177
let text = sprintf " %s\n %s" title changes in
143
178
let fallback = sprintf " [%s] %s - %s" (Slack. git_short_sha_hash sha) commit.message commit.author.name in
0 commit comments