Posting svn commit notifications to slack
We are trying out slack as a communication tool at work, and i thought it would be nice to post notifications about commits to our svn repository to the channel i set up for project stuff.
So the plan is to setup a post-commit hook on the svn host which calls into slacks webapi.
Posting to the slack webapi
I have already described howto post to slack channels from the shell in another post.
To make it easier for to send the commit information to slack, i modified the script from the above mentioned post to accept a svn repo location and a revision number (which is what we get passed into the svn hook handler) instead of the message.
Also the user and channel name are fix.
Now it looks like this:
As you can see, there is some converting and replacing magic involved, to end up with a message which curl can hand over as valid json.
The SVN side
Place the above script in a location where it is callable from svn (e.g. /usr/bin) and give it the appropriate execution rights.
Next we have to tell svn to call the script and pass it the correct parameters after each commit to our repository(-branch).
To do this, edit the post-commit script of your repository. Its usually located in <path-to-repo>/hooks/post-commit
.
Add the following lines:
And we are done here. A commit should now produce a post displaying the commit message in the selected slack channel: