Skip to content

Instantly share code, notes, and snippets.

@tritonrc
Created April 21, 2011 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tritonrc/935035 to your computer and use it in GitHub Desktop.
Save tritonrc/935035 to your computer and use it in GitHub Desktop.
Sinatra based Github hook that sends commit information to a Jabber chat room
require 'rubygems'
require 'sinatra'
require 'xmpp4r'
require 'xmpp4r/muc'
require 'json'
CONFIG = YAML.load_file('config.yml')
jid = Jabber::JID::new(CONFIG['user_jid'])
client = Jabber::Client::new(jid)
client.connect(CONFIG['host'])
client.auth(CONFIG['user_password'])
muc = Jabber::MUC::SimpleMUCClient.new(client)
muc.join(Jabber::JID.new(CONFIG['muc_jid']))
before do
if CONFIG.keys.include?('prefix')
request.path_info = request.path_info.gsub(/^#{CONFIG['prefix']}/, '')
end
end
post '/' do
payload = JSON.parse(params[:payload])
return unless payload.keys.include?('repository')
repo = payload['repository']['name']
payload['commits'].each do |c|
muc.say("#{repo}\n#{c['author']['name']}\n#{c['url']}\n#{c['message']}")
end
200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment