File tree Expand file tree Collapse file tree 4 files changed +83
-3
lines changed Expand file tree Collapse file tree 4 files changed +83
-3
lines changed Original file line number Diff line number Diff line change
1
+ (* https://styleguide.github.com/primer/utilities/colors/#background-colors *)
2
+
3
+ let gray = " #f6f8fa"
4
+
5
+ let blue = " #0366d6"
6
+
7
+ let yellow = " #ffd33d"
8
+
9
+ let red = " #d73a49"
10
+
11
+ let green = " #28a745"
12
+
13
+ let purple = " #6f42c1"
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ type commit = {
24
24
type github_user = {
25
25
login: string;
26
26
id: int;
27
+ url: string;
28
+ html_url: string;
29
+ avatar_url: string;
27
30
}
28
31
29
32
type repository = {
@@ -218,12 +221,19 @@ type file = {
218
221
blob_url <ocaml name="url"> : string;
219
222
}
220
223
224
+ type api_commit_stats = {
225
+ total: int;
226
+ additions: int;
227
+ deletions: int;
228
+ }
229
+
221
230
type api_commit = {
222
231
sha: commit_hash;
223
232
commit: inner_commit;
224
233
html_url <ocaml name="url"> : string;
225
234
author: github_user;
226
235
files: file list;
236
+ stats: api_commit_stats;
227
237
}
228
238
229
239
type commit_comment_notification = {
Original file line number Diff line number Diff line change 1
1
open Printf
2
2
open Base
3
- open Devkit
4
3
open Common
5
4
open Github_j
6
5
open Slack_j
@@ -33,6 +32,8 @@ let show_labels = function
33
32
| (labels : label list ) ->
34
33
Some (sprintf " Labels: %s" @@ String. concat ~sep: " , " (List. map ~f: (fun x -> x.name) labels))
35
34
35
+ let pluralize name num suffix = if num = 1 then sprintf " %s" name else String. concat [ name; suffix ]
36
+
36
37
let generate_pull_request_notification notification channel =
37
38
let { action; number; sender; pull_request; repository } = notification in
38
39
let ({ body; title; html_url; labels; _ } : pull_request ) = pull_request in
@@ -302,8 +303,7 @@ let generate_status_notification (cfg : Config_t.config) (notification : status_
302
303
[ main ]
303
304
| _ -> notification_branches
304
305
in
305
- let pluralize s = if Int. equal (List. length branches) 1 then s else sprintf " %ses" s in
306
- [ sprintf " *%s*: %s" (pluralize " Branch" ) (String. concat ~sep: " , " branches) ]
306
+ [ sprintf " *%s*: %s" (pluralize " Branch" (List. length branches) " es" ) (String. concat ~sep: " , " branches) ]
307
307
in
308
308
let summary =
309
309
match target_url with
Original file line number Diff line number Diff line change
1
+ open Base
2
+ open Printf
3
+ open Github_t
4
+ open Slack_t
5
+
6
+ let git_short_sha_hash hash = String. sub ~pos: 0 ~len: 8 hash
7
+
8
+ let empty_attachment =
9
+ {
10
+ mrkdwn_in = None ;
11
+ fallback = None ;
12
+ color = None ;
13
+ pretext = None ;
14
+ author_name = None ;
15
+ author_link = None ;
16
+ author_icon = None ;
17
+ title = None ;
18
+ title_link = None ;
19
+ text = None ;
20
+ fields = None ;
21
+ image_url = None ;
22
+ thumb_url = None ;
23
+ ts = None ;
24
+ footer = None ;
25
+ }
26
+
27
+ let base_attachment (repository : repository ) =
28
+ { empty_attachment with footer = Some (sprintf " <%s|%s>" repository.url repository.full_name) }
29
+
30
+ let pp_file (file : file ) = sprintf " <%s|%s>" file.url (Mrkdwn. escape_mrkdwn file.filename)
31
+
32
+ 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
35
+ let title = sprintf " `<%s|%s>` *%s - %s*" url (git_short_sha_hash sha) commit.message commit.author.name in
36
+ let num_change = List. length files in
37
+ let changes =
38
+ sprintf " %d %s with %d %s and %d %s:" num_change
39
+ (Slack. pluralize " changed file" num_change " s" )
40
+ stats.additions
41
+ (Slack. pluralize " addition" stats.additions " s" )
42
+ stats.deletions
43
+ (Slack. pluralize " deletion" stats.deletions " s" )
44
+ in
45
+ let files = get_files () |> String. concat ~sep: " \n " in
46
+ let text = sprintf " %s\n %s\n %s" title changes files in
47
+ let fallback = sprintf " [%s] %s - %s" (git_short_sha_hash sha) commit.message commit.author.name in
48
+ {
49
+ (base_attachment repository) with
50
+ author_name = Some author.login;
51
+ author_link = Some author.html_url;
52
+ author_icon = Some author.avatar_url;
53
+ color = Some Colors. gray;
54
+ mrkdwn_in = Some [ " text" ];
55
+ text = Some text;
56
+ fallback = Some fallback;
57
+ }
You can’t perform that action at this time.
0 commit comments