Skip to content
Browse files

Added GitHub status script

  • Loading branch information...
1 parent e703a81 commit 9d0f4c1b96cf647af83665d4b716dc009c7f8660 @voke voke committed
Showing with 57 additions and 0 deletions.
  1. +57 −0 src/scripts/github-status.coffee
View
57 src/scripts/github-status.coffee
@@ -0,0 +1,57 @@
+# Description:
+# Show current GitHub status and messages
+#
+# Dependencies:
+# None
+#
+# Configuration:
+# None
+#
+# Commands:
+# hubot github status - Returns the current system status and timestamp.
+# hubot github status last - Returns the last human communication, status, and timestamp.
+# hubot github status messages - Returns the most recent human communications with status and timestamp.
+#
+# Author:
+# voke
+
+module.exports = (robot) ->
+ robot.respond /github status$/i, (msg) ->
+ status msg
+
+ robot.respond /github status last$/i, (msg) ->
+ lastMessage msg
+
+ robot.respond /github status messages$/i, (msg) ->
+ statusMessages msg
+
+# NOTE: messages contains new lines for some reason.
+formatString = (string) ->
+ decodeURIComponent(string.replace(/(\n)/gm," "))
+
+status = (msg) ->
+ msg.http('https://status.github.com/api/status.json')
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ now = new Date()
+ date = new Date(json['last_updated'])
+ secondsAgo = Math.round((now.getTime() - date.getTime()) / 1000)
+ msg.send "Status: #{json['status']} (#{secondsAgo} seconds ago)"
+
+lastMessage = (msg) ->
+ msg.http('https://status.github.com/api/last-message.json')
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ date = new Date(json['created_on'])
+ msg.send "Status: #{json['status']}\n" +
+ "Message: #{formatString(json['body'])}\n" +
+ "Date: #{date.toLocaleString()}"
+
+statusMessages = (msg) ->
+ msg.http('https://status.github.com/api/messages.json')
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ buildMessage = (message) ->
+ date = new Date(message['created_on'])
+ "[#{message['status']}] #{formatString(message['body'])} (#{date.toLocaleString()})"
+ msg.send (buildMessage message for message in json).join('\n')

0 comments on commit 9d0f4c1

Please sign in to comment.
Something went wrong with that request. Please try again.