Skip to content

Commit e6dea03

Browse files
committed
Add support for Zulip webhook
1 parent 59031ec commit e6dea03

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*-token
22
custom-uri
33
discord-webhook
4+
zulip-apikey
45
poll
56
api
67
worker

server.sml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fun finish id =
136136
Posix.IO.close fd;
137137
GitHub.set_status f cakeml_sha status;
138138
Slack.send_message message;
139-
Discord.send_message (Discord.compose_message f status job_pr);
139+
Zulip.send_message (Zulip.compose_message f status job_pr);
140140
send_email subject (String.concat[body,"\n"]);
141141
()
142142
end

serverLib.sml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,56 @@ structure Discord = struct
667667
end
668668
end
669669

670+
structure Zulip = struct
671+
val zulip_apikey = until_space (file_to_string "zulip-apikey")
672+
val postMessage_endpoint = "https://hol.zulipchat.com/api/v1/messages"
673+
fun postMessage_curl_cmd text = (curl_path,["--silent","--show-error",
674+
"--request","POST",
675+
"--user",String.concat["regression-bot@hol.zulipchat.com:",zulip_apikey],
676+
"--user-agent","CakeML-Regression-Server",
677+
"--write-out","%{http_code}",
678+
"--data-urlencode","type=stream",
679+
"--data-urlencode","to=Notifications",
680+
"--data-urlencode","topic=Regression",
681+
"--data-urlencode",String.concat["content=",text],
682+
postMessage_endpoint])
683+
684+
fun compose_message id status job_pr =
685+
let
686+
val status_str = String.map Char.toLower (status_to_string status)
687+
val url = String.concat [server, "/job/", id]
688+
val emoji =
689+
case status of
690+
Success => ":check:"
691+
| Failure => ":cross_mark:"
692+
| Aborted => ":orange_circle:"
693+
| Pending =>
694+
cgi_die 500 ["Error composing Zulip message: job ", id, " was pending"]
695+
fun pr_md_link pr =
696+
let val pr_no = extract_prefix_trimr "#" pr
697+
val pull_url = String.concat [cakeml_github, "/pull/", pr_no]
698+
in String.concat ["[#", pr_no, "](", pull_url, ")"] end
699+
val description =
700+
case job_pr of
701+
NONE => "On master"
702+
| SOME (pr, branch) =>
703+
String.concatWith " " ["Pull request", pr_md_link (Substring.string pr),
704+
Substring.string (trim_ws branch)]
705+
in
706+
String.concat ["[Job ",id,"](",url,"): ",status_str," ",emoji,"\n",description]
707+
end
708+
709+
fun send_message text =
710+
let
711+
val cmd = postMessage_curl_cmd text
712+
val response = system_output (cgi_die 500) cmd
713+
in
714+
cgi_assert
715+
(String.isPrefix "204" response)
716+
500 ["Error sending Zulip message\n",response]
717+
end
718+
end
719+
670720
(* We ask for the first 100 PRs/labels below. GitHub requires some
671721
limit. We don't expect to hit 100. *)
672722
val cakeml_query = String.concat [

0 commit comments

Comments
 (0)