@@ -5,6 +5,19 @@ open Slack_t
5
5
open Common
6
6
open Mrkdwn
7
7
8
+ let color_of_state ?(draft = false ) ?(merged = false ) state =
9
+ match draft with
10
+ | true -> Colors. gray
11
+ | false ->
12
+ match merged with
13
+ | true -> Colors. purple
14
+ | false ->
15
+ match state with
16
+ | Open -> Colors. green
17
+ | Closed -> Colors. red
18
+
19
+ let gh_name_of_string = sprintf " @%s"
20
+
8
21
let empty_attachment =
9
22
{
10
23
mrkdwn_in = None ;
@@ -27,6 +40,87 @@ let empty_attachment =
27
40
let base_attachment (repository : repository ) =
28
41
{ empty_attachment with footer = Some (sprintf " <%s|%s>" repository.url (escape_mrkdwn repository.full_name)) }
29
42
43
+ let pp_label (label : label ) = label.name
44
+
45
+ let pp_github_user (user : github_user ) = gh_name_of_string user.login
46
+
47
+ let pp_github_team (team : github_team ) = gh_name_of_string team.slug
48
+
49
+ let populate_pull_request repository (pull_request : pull_request ) =
50
+ let ({
51
+ body;
52
+ title;
53
+ number;
54
+ html_url;
55
+ user;
56
+ assignees;
57
+ comments;
58
+ labels;
59
+ requested_reviewers;
60
+ requested_teams;
61
+ state;
62
+ draft;
63
+ merged;
64
+ _;
65
+ }
66
+ : pull_request)
67
+ =
68
+ pull_request
69
+ in
70
+ let get_reviewers () =
71
+ List. concat [ List. map requested_reviewers ~f: pp_github_user; List. map requested_teams ~f: pp_github_team ]
72
+ in
73
+ let fields =
74
+ [
75
+ " Assignees" , List. map assignees ~f: pp_github_user;
76
+ " Labels" , List. map labels ~f: pp_label;
77
+ " Comments" , [ Int. to_string comments ];
78
+ " Reviewers" , get_reviewers () ;
79
+ ]
80
+ |> List. filter_map ~f: (fun (t , v ) -> if List. is_empty v then None else Some (t, String. concat v ~sep: " ," ))
81
+ |> List. map ~f: (fun (t , v ) -> { title = Some t; value = v })
82
+ in
83
+ let get_title () = sprintf " #%d %s" number (Mrkdwn. escape_mrkdwn title) in
84
+ {
85
+ (base_attachment repository) with
86
+ author_name = Some user.login;
87
+ author_link = Some user.html_url;
88
+ author_icon = Some user.avatar_url;
89
+ color = Some (color_of_state ~draft ~merged state);
90
+ fields = Some fields;
91
+ mrkdwn_in = Some [ " text" ];
92
+ title = Some (get_title () );
93
+ title_link = Some html_url;
94
+ fallback = Some (sprintf " [%s] %s" repository.full_name title);
95
+ text = Some (Mrkdwn. mrkdwn_of_markdown body);
96
+ }
97
+
98
+ let populate_issue repository (issue : issue ) =
99
+ let ({ body; title; number; html_url; user; assignees; comments; labels; state; _ } : issue ) = issue in
100
+ let fields =
101
+ [
102
+ " Assignees" , List. map assignees ~f: pp_github_user;
103
+ " Labels" , List. map labels ~f: pp_label;
104
+ " Comments" , [ Int. to_string comments ];
105
+ ]
106
+ |> List. filter_map ~f: (fun (t , v ) -> if List. is_empty v then None else Some (t, String. concat v ~sep: " ," ))
107
+ |> List. map ~f: (fun (t , v ) -> { title = Some t; value = v })
108
+ in
109
+ let get_title () = sprintf " #%d %s" number (Mrkdwn. escape_mrkdwn title) in
110
+ {
111
+ (base_attachment repository) with
112
+ author_name = Some user.login;
113
+ author_link = Some user.html_url;
114
+ author_icon = Some user.avatar_url;
115
+ color = Some (color_of_state state);
116
+ fields = Some fields;
117
+ mrkdwn_in = Some [ " text" ];
118
+ title = Some (get_title () );
119
+ title_link = Some html_url;
120
+ fallback = Some (sprintf " [%s] %s" repository.full_name title);
121
+ text = Some (Mrkdwn. mrkdwn_of_markdown body);
122
+ }
123
+
30
124
let populate_commit repository (commit : api_commit ) =
31
125
let ({ sha; commit; url; author; files; _ } : api_commit ) = commit in
32
126
let title =
0 commit comments