Skip to content

Instantly share code, notes, and snippets.

@drfeelngood
Created September 10, 2011 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drfeelngood/1208193 to your computer and use it in GitHub Desktop.
Save drfeelngood/1208193 to your computer and use it in GitHub Desktop.
Git post-receive hook that broadcasts commit messages via jabber
# post-receive
#
# Broadcast commit messages when pushed to the repositories master branch.
#
#== Git Configuration Example
# [notify]
# jabber = foo bar
#
require 'rubygems'
require 'jabber4r/jabber4r'
user_suffix = "jabber.example.com"
host = "jabber.example.com"
jid = "git"
password = "g!t"
old_rev, new_rev, refname = STDIN.read.split(/\s/)
branch = refname.split('/').last
recipients = `git config notify.jabber`.split(" ")
subject = `cat #{File.join(File.dirname(__FILE__), "..", "description")}`
body = `git log #{old_rev}..#{new_rev} --no-merges --name-only`
if branch == 'master'
begin
session = Jabber::Session.bind("#{jid}@#{host}/resource", password)
recipients.each do |to|
message = session.new_message("#{to}@#{user_suffix}")
message.set_subject(subject)
message.set_body(body)
message.send
end
rescue Object => boom
$stderr.puts "#{boom.class}: #{boom.message}"
ensure
session.release rescue nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment