Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 9d0f4c1

Browse files
committed
Added GitHub status script
1 parent e703a81 commit 9d0f4c1

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/scripts/github-status.coffee

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Description:
2+
# Show current GitHub status and messages
3+
#
4+
# Dependencies:
5+
# None
6+
#
7+
# Configuration:
8+
# None
9+
#
10+
# Commands:
11+
# hubot github status - Returns the current system status and timestamp.
12+
# hubot github status last - Returns the last human communication, status, and timestamp.
13+
# hubot github status messages - Returns the most recent human communications with status and timestamp.
14+
#
15+
# Author:
16+
# voke
17+
18+
module.exports = (robot) ->
19+
robot.respond /github status$/i, (msg) ->
20+
status msg
21+
22+
robot.respond /github status last$/i, (msg) ->
23+
lastMessage msg
24+
25+
robot.respond /github status messages$/i, (msg) ->
26+
statusMessages msg
27+
28+
# NOTE: messages contains new lines for some reason.
29+
formatString = (string) ->
30+
decodeURIComponent(string.replace(/(\n)/gm," "))
31+
32+
status = (msg) ->
33+
msg.http('https://status.github.com/api/status.json')
34+
.get() (err, res, body) ->
35+
json = JSON.parse(body)
36+
now = new Date()
37+
date = new Date(json['last_updated'])
38+
secondsAgo = Math.round((now.getTime() - date.getTime()) / 1000)
39+
msg.send "Status: #{json['status']} (#{secondsAgo} seconds ago)"
40+
41+
lastMessage = (msg) ->
42+
msg.http('https://status.github.com/api/last-message.json')
43+
.get() (err, res, body) ->
44+
json = JSON.parse(body)
45+
date = new Date(json['created_on'])
46+
msg.send "Status: #{json['status']}\n" +
47+
"Message: #{formatString(json['body'])}\n" +
48+
"Date: #{date.toLocaleString()}"
49+
50+
statusMessages = (msg) ->
51+
msg.http('https://status.github.com/api/messages.json')
52+
.get() (err, res, body) ->
53+
json = JSON.parse(body)
54+
buildMessage = (message) ->
55+
date = new Date(message['created_on'])
56+
"[#{message['status']}] #{formatString(message['body'])} (#{date.toLocaleString()})"
57+
msg.send (buildMessage message for message in json).join('\n')

0 commit comments

Comments
 (0)