Skip to content

Instantly share code, notes, and snippets.

@soopa
Created July 28, 2013 06:16
Show Gist options
  • Save soopa/6097618 to your computer and use it in GitHub Desktop.
Save soopa/6097618 to your computer and use it in GitHub Desktop.
The ol' Gowalla GitHub Issues Monitor for Campfire, for keepsakes
require 'rubygems'
require 'hashie'
require 'httparty'
require 'json'
module Gowalla
class Issues
include HTTParty
base_uri 'https://api.github.com'
basic_auth ENV['GITHUB_USER'], ENV['GITHUB_PASS']
format :json
def self.issue(url)
get(url).parsed_response rescue nil
end
def self.events
get("/repos/#{ENV['GITHUB_REPO']}/issues/events").parsed_response rescue nil
end
end
class Campfire
include HTTParty
base_uri 'https://gowalla.campfirenow.com'
basic_auth ENV['CAMPFIRE_TOKEN'], 'X'
def self.send(message)
post("/room/#{ENV['CAMPFIRE_ROOM']}/speak.json", :body => { "message" => { "body" => message } }.to_json, :headers => { "Content-Type" => "application/json"} ) rescue nil
end
end
class Monitor
def self.issues_events
cache = []
loop do
events = Gowalla::Issues.events
unless cache.empty?
events.each do |event|
event = Hashie::Mash.new(event)
break if cache.first['url'] == event.url
case event.event
when 'closed'
message = "#{event.actor.login} closed"
when 'reopened'
message = "#{event.actor.login} reopened"
when 'assigned'
message = "#{event.actor.login} was assigned to"
end
unless message.blank?
url = event.issue.url.sub('api', 'www').sub('repos/', '')
message << " \"#{event.issue.title}\" (##{event.issue.number}) in #{ENV['GITHUB_REPO']}: #{url}"
post = Gowalla::Campfire.send(message)
puts message if ENV['VERBOSE']
end
end
end
cache = events
sleep 30
end
end
end
end
Gowalla::Monitor.issues_events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment