24 Sep 2010 groom   » (Journeyer)

Posting SVN commits to an IRC channel

Everybody may be aware of svn mailers that post commit logs to a mailing list or several email address. I found more useful to have a notification on my favourite IRC channel.

For people interested in IRC notification of SVN commits, here is a python script that will do the trick.


#!/usr/bin/python
import sys
from irclib import *


class SVNBot(SimpleIRCClient): def __init__(self, server, port, target, repo, rev, author, log): SimpleIRCClient.__init__(self)

self.target = target self.repo = repo self.rev = rev self.author = author self.log = log self.msg = 'new commit on ' + repo + ' r' + rev + ' by ' + author + ': ' + log self.connect(server, port, 'svnbot')

def on_nicknameinuse(self, c, e): c.nick(c.get_nickname() + '_') def on_welcome(self, c, e): if (is_channel(self.target)): self.connection.join(self.target) else: self.connection.notice(self.target, self.msg) self.connection.quit()

def on_join(self, c, e): nick = nm_to_n(e.source()) if nick == c.get_nickname(): self.connection.notice(self.target, self.msg) self.connection.quit()

def on_quit(self, c, e): nick = nm_to_n(e.source()) if nick == c.get_nickname(): self.connection.disconnect() sys.exit(0)

def main(): if len(sys.argv) != 7: print 'Usage: ' + sys.argv[0] + ' <server[:port]> <target> <repo> <revnum> <author> <log>' sys.exit(1)

s = sys.argv[1].split(':', 1) server = s[0] if len(s) == 2: try: port = int(s[1]) except ValueError: print 'Error: Erroneous port.' sys.exit(1) else: port = 6667 target = sys.argv[2] repo = sys.argv[3] revnum = sys.argv[4] author = sys.argv[5] log = sys.argv[6] bot = SVNBot(server, port, target, repo, revnum, author, log) bot.start()

if __name__ == '__main__': main()

This script should be callable from the hooks/post-commit file as follow:


REPOS="$1"
REV="$2"
AUTHOR=`/usr/bin/svnlook author "$REPOS"`
LOG=`/usr/bin/svnlook log "$REPOS"`
/usr/local/bin/svnbot.py "irc.server" "#irc.chan" "$REPOS"
"$REV" "$AUTHOR" "$LOG"

Now, happy commits!

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!