Created
February 6, 2013 13:57
-
-
Save llimllib/4722648 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'open-uri' | |
class Hubstat < Linkbot::Plugin | |
@@hipchat = Linkbot::Config["plugins"]["hipchat"] | |
Linkbot::Plugin.register('hubstat', self, { | |
:message => { :regex => /\A!hubstat/, :handler => :on_message, :help => :help } | |
}) | |
def self.help | |
'!hubstat - see whether your trouble with GitHub is just you' | |
end | |
def self.on_message(message, matches) | |
colors = { | |
"good" => "green", | |
"minor" => "yellow", | |
"major" => "red" | |
} | |
message = JSON.parse(open('https://status.github.com/api/last-message.json').read) | |
color = colors.fetch(message['status'], "gray") | |
message = "As of #{message["created_on"]}, GitHub is <a href='https://status.github.com/'>reporting</a>: #{message["body"]}" | |
self.hicpchat_send(color, message) | |
end | |
def self.hipchat_send(color, message) | |
message = CGI.escape(message) | |
url = "https://api.hipchat.com/v1/rooms/message?" \ | |
+ "auth_token=#{@@hipchat['api_token']}&" \ | |
+ "message=#{message}&" \ | |
+ "color=#{color}&" \ | |
+ "room_id=#{@@hipchat['room']}&" \ | |
+ "from=GitHub+Status" | |
puts "sending message to hipchat url #{url}" | |
open(url) | |
rescue => e | |
puts e.inspect | |
puts e.backtrace.join("\n") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment