Skip to content

Commit 18f4aa0

Browse files
committed
Send Slack message when jobs finish
1 parent 0e66d49 commit 18f4aa0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

server.sml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ fun finish id =
125125
case read_job_pr inp of
126126
NONE => "master"
127127
| SOME (_, branch) => Substring.string (trim_ws branch)
128+
val subject = String.concat[status_to_string status,": Job ",f," ",branch]
129+
val body = String.concat["See ",server,"/job/",f]
128130
in
129131
TextIO.closeIn inp;
130132
Posix.IO.close fd;
131133
GitHub.set_status f sha status;
132-
send_email (String.concat[status_to_string status,": Job ",f," ",branch])
133-
(String.concat["See ",server,"/job/",f,"\n"]);
134+
send_email subject (String.concat[body,"\n"]);
135+
Slack.send_message (String.concat[subject," - ",body]);
134136
()
135137
end
136138

serverLib.sml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,28 @@ structure GitHub = struct
365365
end
366366
end
367367

368+
structure Slack = struct
369+
val token = until_space (file_to_string "slack-token")
370+
val channel = "CCKESLBJQ"
371+
val postMessage_endpoint = "https://slack.com/api/chat.postMessage"
372+
fun postMessage_curl_cmd text = (curl_path,["--silent","--show-error",
373+
"--header",String.concat["Authorization: Bearer ",token],
374+
"--header","Content-type: application/json;charset=utf-8",
375+
"--request","POST",
376+
"--data",String.concat["{\"channel\":\"",channel,"\",",
377+
"\"text\":\"",text,"\"}"],
378+
postMessage_endpoint])
379+
fun send_message text =
380+
let
381+
val text = String.translate (fn c => if c = #"\"" then """ else String.str c) text
382+
val cmd = postMessage_curl_cmd text
383+
val response = system_output (cgi_die 500) cmd
384+
in
385+
cgi_assert
386+
(String.isPrefix "{\"ok\":true" response)
387+
500 ["Error sending Slack message\n",response]
388+
end
389+
end
368390

369391
(* We ask for the first 100 PRs/labels below. GitHub requires some
370392
limit. We don't expect to hit 100. *)

0 commit comments

Comments
 (0)