Writing an irc bot for svn commit notification
October 15, 2009 – 1:40 pm by Stefano MAESTRIRecently I’ve started working with a new team. Since we are based in 2 different site a bit far each other we are using extensively an IRC channel to communicate.
We are using subversion as SCM and we need to keep all members of the team up to date about svn commits. The solution I’ve put in place during an insomniac night in an hotel is a post-commit hook invoking an irc bot script written in perl connecting to the server and shotting a message there. Quite simple, and it is taking its goal.
In $SVN_REPOSITORY/hooks edit and make executable the file post-commit
#!/bin/sh REPOS="$1" TXN="$2" SVNLOOK=/usr/bin/svnlook # get last commit message COMMIT=`$SVNLOOK log "$REPOS"` USER=`whoami` # call bot with arguments reposname, revison and commit message in one string /usr/bin/perl /usr/local/bin/svn_irc_bot.pl "$USER $REPOS r$TXN: $COMMIT" # all checks passed, so allow the commit exit 0
then edit and make executable the file /usr/local/bin/svn_irc_bot.pl
#!/usr/bin/perl -w #svn_irc_bot.pl my $server = ""; #put here your address my $port = 6667; my $nick = "svn_bot"; my $ident = "svn_bot"; my $realname = "svn_bot"; my $chan = "#YourChannel";#put here your channel name my $pass = "svn_bot"; my $svn_commit = $ARGV[0]; use IO::Socket; my $irc=IO::Socket::INET->new( PeerAddr=>$server, PeerPort=>$port, Proto=>'tcp') or die "DEAD!"; #print $irc "USER $ident $ident $ident $ident :$realname\n"; print $irc "NICK $nick\r\n"; #print $irc "PRIVMSG nickserv/@/services.dal.net :identify $pass\n"; print $irc "USER $ident 8 * :Perl IRC Hacks Robot\r\n"; print $irc "join $chan\n"; while(my $in = <$irc>) { if($in=~/004/) { print $irc "PRIVMSG $chan :$svn_commit \n"; last; } if($in=~/^PING(.*)$/i) { print $irc "PONG :$1\n"; } } close($irc); #EOF
If user named “fooUser” make a commit on “fooRepository” for release 409 with a comment like “this is a fooComment” on irc channel you will get something like:
<svn_bot> fooUser fooRepository r409: this is a fooComment
I took the base of code here. Then I’ve modified it a little to get result I like.













2 Responses to “Writing an irc bot for svn commit notification”
An interesting idea to improve team communication. Another idea that comes to my mind is installing a continous integration tool like Hudson or Cruise Control. These tools can also monitor source repositories for commits, then start the build process and finally send out reports about the changes and the build report. With this you get even more information about the common state of your project.
By Marc on Oct 17, 2009
Yes of course. We are using hudson too. BTW the post-commit hook for that is quite simple:
lynx -dump http://HUDSON_HOST/hudson/job/JOB_NAME/build
of course you have to substitute HUDSON_HOST and JOB_NAME with properly value
By Stefano MAESTRI on Oct 17, 2009