Search code examples
batch-filesvntortoisesvnpost-commit-hook

Tortoise SVN Post-Commit Hook Windows


I'm working on a simple slack integration for SVN projects via a client side post-commit hook in Windows Tortoise SVN using curl to send JSON. I would like to post some basic information, ideally revision number and comment when a commit is made. I added a post-commit client side hook, that executes a postcommit.bat file that succeeds in sending my slack channel a message. What I can't get working is including the passed in variables from tortoise. According to tortoise a SVN client side hook post-commit will include the following argument PATH DEPTH MESSAGEFILE REVISION ERROR CWD https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-settings.html

Here is my working code, that sends a static string (not including message/revision to my slack channel):

C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRETSERVICE -d "{\"text\":\"Test message\"}"

I would like to do something like this, but the following code does not, it simply posts "RevMessage", or in other words the parameters are not properly passed:

C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRETSERVICE -d "{\"text\":\"Rev%REVISION%Message%MESSAGE%\"}"

Solution

  • Okay, this may have been so specific (judging by view count) that I was bound to answer it myself, lol. Anyway, perhaps someone else will find this useful, here is what ended up working for me. First variables need to be set from arguments, then they can be referenced as shown:

        set tsvnPath=%1
        set tsvnDepth=%2
        set tsvnMsgFile=%3
        set /p THEMSG=<%3
        set tsvnRevision=%4
        set tsvnError=%5
        set tsvnCwd=%6
        C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRET -d "{\"text\":\"MSG %THEMSG% REV %tsvnRevision%\"}"