Yammer and SVN post-commit hooks

If you don’t know what Yammer is, it is a twitter like communication tool for your company:

Yammer is a tool for making companies and organizations more productive through the exchange of short frequent answers to one simple question: “What are you working on?”

Whats nice about Yammer is it is an internal tool that you can quickly communicate with everyone, well anyone listening, in your company. Answers to questions come quickly and from the appropriate party without much effort on either end and notifications to everyone are a snap.

The notifications is what got me thinking about Subversion and post-commit hooks. Subversion provides hooks that allow you to trigger scripts based on a repository event. So, I set up a script that retrieves information about the latest commit to the repository formats an email which is sent to Yammer and published. Now, when someone commits to the repository, everyone is automatically notified without the developer having to write an email and send it to everyone that needs to know about it.

Another unforeseen benefit of this system is that everyone has gotten much better at their SVN comments for their commit. I would imagine this is because they get instant feedback about inadequate comments when everyone see it in Yammer.

On to the resources – SVN hooks are pretty easy to implement and provided by default. They reside in each repository you create in a ‘hooks’ directory {SVN_ROOT}/{REPOSITORY}/hooks. There is a provided template for each type of hook that SVN supports. The script can be any type of script (shell scripts, Python scripts etc), it just needs to have the same name as the supplied template file. For our Yammer script I dusted off the .bat script skills to retrieve the commit and send an email. To send the email I downloaded blat to handle sending the email to Yammer. Finally we create an email for out SVN user and a yammer account using the svn user email.

So here is the list of what we have so far:

  • SVN Repositoy and access to the hooks directory
  • Email address for the SVN user
  • Yammer account using the SVN user’s email address
  • Some way to send an email (Blat)
  • SVN post-commit hook script (post-commit.bat)

Now on to the contents of the script – The post commit hook receives 2 arguments, the name of the repository and the revision. The script uses svnlook, the repository name and revision to retrieve the details (message and author) of the commit. Then usign the commit details the script creates a text file that Blat uses as the email body and sends the email to Yammer.

Here is the actual script (names have been changed to protect the innocent):
@echo off

::: ARGUMENTS :::::::::::::::::::::::::::::::::::::::

::: GENERAL INFO ::::::::::::::::::::::::::::::::::::
SET MESSAGE_FILE=%DIR%/message.txt

::: SVN INFO ::::::::::::::::::::::::::::::::::::::::

::: Get the author ::::::::::::::::::::::::::::::::::
For /F “Tokens=*” %%I in (‘svnlook author %REPOS% -r %REV%’) Do Set author=%%I

::: Get the log messsage ::::::::::::::::::::::::::::::::::
For /F “Tokens=*” %%I in (‘svnlook log %REPOS% -r %REV%’) Do Set log=%%I

::: Set the message body ::::::::::::::::::::::::::::::::::
ECHO Commit – rev %REV% (#%author%): ‘%log%’ – %REPOS% > %MESSAGE_FILE%

::: EMAIL INFO ::::::::::::::::::::::::::::::::::::::

set to=-to yammer@yammer.com

set subj=-s “SVN Commit (Revision %REV%)”

set server=-server mail.domain.com

set debug=-debug -log blat.log -timestamp

set auth=-u email@domain.com -pw yourpasswordhere

set from=-f email@domain.com

::: SEND THE EMAIL ::::::::::::::::::::::::::::::::::
C:/pathtoyourrepos/_tools/blat/blat %MESSAGE_FILE% %server% %to% %from% %subj% %auth% %debug%

Or you can download the script:


Leave a Reply

Your email address will not be published. Required fields are marked *