Skip to content

Commit f10278d

Browse files
committed
rename slack req/res atd types so they're not webhook-specific
Slack Webhooks and Web API should be able to share the same payload structure.
1 parent 8a78d71 commit f10278d

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

lib/api.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ module type Github = sig
99
end
1010

1111
module type Slack = sig
12-
val send_notification : chan:string -> msg:webhook_notification -> url:string -> (unit, string) Result.t Lwt.t
12+
val send_notification : chan:string -> msg:post_message_req -> url:string -> (unit, string) Result.t Lwt.t
1313
end

lib/api_local.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ end
2222

2323
module Slack : Api.Slack = struct
2424
let send_notification ~chan ~msg ~url:_ =
25-
let json =
26-
msg |> Slack_j.string_of_webhook_notification |> Yojson.Basic.from_string |> Yojson.Basic.pretty_to_string
27-
in
25+
let json = msg |> Slack_j.string_of_post_message_req |> Yojson.Basic.from_string |> Yojson.Basic.pretty_to_string in
2826
Stdio.printf "will notify #%s\n" chan;
2927
Stdio.printf "%s\n" json;
3028
Lwt.return @@ Ok ()
@@ -46,7 +44,7 @@ module Slack_json : Api.Slack = struct
4644
let log = Log.from "slack"
4745

4846
let send_notification ~chan ~msg ~url:_ =
49-
let json = Slack_j.string_of_webhook_notification msg in
47+
let json = Slack_j.string_of_post_message_req msg in
5048
log#info "will notify %s" chan;
5149
let url = Uri.of_string "https://api.slack.com/docs/messages/builder" in
5250
let url = Uri.add_query_param url ("msg", [ json ]) in

lib/api_remote.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Slack : Api.Slack = struct
5151
let log = Log.from "slack"
5252

5353
let send_notification ~chan ~msg ~url =
54-
let data = Slack_j.string_of_webhook_notification msg in
54+
let data = Slack_j.string_of_post_message_req msg in
5555
let body = `Raw ("application/json", data) in
5656
log#info "sending to %s : %s" chan data;
5757
match%lwt http_request ~body `POST url with

lib/slack.atd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
type webhook_notification_field = {
1+
type message_field = {
22
?title: string nullable;
33
value: string;
44
}
55

6-
type webhook_notification_attachment = {
6+
type message_attachment = {
77
fallback: string nullable;
88
?mrkdwn_in: string list nullable;
99
?color: string nullable;
@@ -14,18 +14,18 @@ type webhook_notification_attachment = {
1414
?title: string nullable;
1515
?title_link: string nullable;
1616
?text: string nullable;
17-
?fields: webhook_notification_field list nullable;
17+
?fields: message_field list nullable;
1818
?image_url: string nullable;
1919
?thumb_url: string nullable;
2020
?ts: int nullable;
2121
?footer: string nullable;
2222
}
2323

24-
type notification_section_block_type = [
24+
type message_section_block_type = [
2525
Section <json name="section">
2626
] <ocaml repr="classic">
2727

28-
type notification_divider_block_type = [
28+
type message_divider_block_type = [
2929
Divider <json name="divider">
3030
] <ocaml repr="classic">
3131

@@ -39,22 +39,22 @@ type text_object = {
3939
text: string;
4040
}
4141

42-
type webhook_notification_text_block = {
43-
notification_type <json name="type"> : notification_section_block_type;
42+
type message_text_block = {
43+
message_type <json name="type"> : message_section_block_type;
4444
text: text_object;
4545
}
4646

47-
type webhook_notification_divider_block = {
48-
notification_type <json name="type"> : notification_divider_block_type;
47+
type message_divider_block = {
48+
message_type <json name="type"> : message_divider_block_type;
4949
}
5050

51-
type webhook_notification_block = [
52-
Text of webhook_notification_text_block
53-
| Divider of webhook_notification_divider_block
51+
type message_block = [
52+
Text of message_text_block
53+
| Divider of message_divider_block
5454
] <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
5555

56-
type webhook_notification = {
56+
type post_message_req = {
5757
?text: string nullable;
58-
?attachments: webhook_notification_attachment list nullable;
59-
?blocks: webhook_notification_block list nullable;
58+
?attachments: message_attachment list nullable;
59+
?blocks: message_block list nullable;
6060
}

src/monorobot.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let check_gh_action file json config secrets state =
4646
let check_slack_action url file =
4747
let data = Stdio.In_channel.read_all file in
4848
let chan = Printf.sprintf "webhook %s" url in
49-
match Slack_j.webhook_notification_of_string data with
49+
match Slack_j.post_message_req_of_string data with
5050
| exception exn -> log#error ~exn "unable to parse notification"
5151
| msg ->
5252
Lwt_main.run

0 commit comments

Comments
 (0)