Created
September 10, 2011 11:15
-
-
Save drfeelngood/1208193 to your computer and use it in GitHub Desktop.
Git post-receive hook that broadcasts commit messages via jabber
This file contains 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
# 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