@@ -667,6 +667,56 @@ structure Discord = struct
667
667
end
668
668
end
669
669
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
+
670
720
(* We ask for the first 100 PRs/labels below. GitHub requires some
671
721
limit. We don't expect to hit 100. *)
672
722
val cakeml_query = String.concat [
0 commit comments