Monitoring SVN commits with Twitter
Posted by Steve Lounsbury on December 11th, 2008
Like a lot of developers, we use SVN on a day to day basis. I can’t imagine working without it. We’ve been using it for over a year now. Svnlook on revision 1 give me this:
[steve@76design ~]$ svnlook info /svn -r 1
steve
2007-08-23 18:23:03 -0400 (Thu, 23 Aug 2007)
23
Created folder remotely
And svnlook youngest gives me this:
[steve@76design ~]$ svnlook youngest /svn
6567
In a year we have over 6500 commits and many projects contained in that (now not so little) repository. Given that there are so many commits going on, we thought it would be useful to have a feed of commits happening in real time. If we had that, we could get a good feel for the activity in the office over the day. One obvious choice for a feed is RSS, and we have that too, but we thought it could be fun to have a twitter stream of our commits.
I did some quick googling and came across a Google code project called twitvn. Unfortunately, due to hosting restrictions, I was unable to get it installed on our svn server. So, like any developer would do, I wrote my own ;)
SVN provides you with some interesting ways to interact with it pre and post commit. I wanted to hook in on post-commit and fire off a twitter message with some details about the commit. Turns out it’s fairly simple to do.
After every commit, if a script is available at [svn path]/hooks/post-commit, SVN will run that script. Two arguments are provided, the svn path and the revision number of the commit. Using these two pieces of info, you can then pull out whatever details you want about that particular commit and choose to do what you want with it. Knowing that, here is the approach I took:
- Get the particulars about the commit using ‘svnlook info’
- Get the modified files using ‘svnlook changed’
- Determine the author and the project that was being committed
- Create a twitter message and send it using Curl
I decided to write it using PHP, mostly because it’s what I know and I wanted to get it done quickly. In order to determine the project, I assumed that the top level folder of the first modified file is the project (this will depend on your repository layout so your mileage may vary here).
The final script is called tweeter.php, grab it here.
In order to run it, drop your twitter account details into CMD_CURL_TWITTER and add this line to your post-commit file:
[path-to-php5-cli] [path-to-tweeter.php] “${REPOS}” “${REV}”
Let me know if you get some use out of it!








