Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinold/9511207 to your computer and use it in GitHub Desktop.
Save kevinold/9511207 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'httparty'
require 'hipchat'
require 'yaml'
LAST_MESSAGE_FILE = 'tmp/last_github_status.yml'
HIPCHAT_API_KEY = 'secret'
HIPCHAT_ROOM = 'Notifications'
class GithubStatus
include HTTParty
base_uri 'https://status.github.com/api'
def current_status
self.class.get('/status.json')
end
def last_message
self.class.get('/last-message.json')
end
def messages
self.class.get('/messages.json')
end
end
hipchat_client = HipChat::Client.new(HIPCHAT_API_KEY)
github_client = GithubStatus.new
last_message = YAML.load(File.read(LAST_MESSAGE_FILE))
current_message = github_client.last_message
should_notify = last_message['created_on'] != current_message['created_on'] &&
(current_message['status'] != 'good' || last_message['status'] != 'good')
if should_notify
message = current_message['body']
color = case current_message['status']
when 'good': 'green'
when 'minor': 'yellow'
when 'major': 'red'
end
hipchat_client[HIPCHAT_ROOM].send('GitHub Status', message, :color => color)
end
File.open(LAST_MESSAGE_FILE, 'w') do |message_file|
message_file.write(current_message.to_yaml)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment