Since I am using Laconica to capture notices from my batch jobs(see Microblogging for Applications) I thought it would be nice to add an account for my Subversion repositories and use the post-commit hook to keep me posted.
I’m not an expert with Subversion so if there is an easier way to get this information please let me know. I use two executions of the svnlook command to get the info and then dirs-changed for the folders involved. My repositories are structured by projects so the first folder is the project name.
This example uses Window batch files:
post-commit.bat
@ECHO OFF :: ************************************************************* :: * this sets the arguments supplied by Subversion * :: ************************************************************* SET REPOS=%1 SET REV=%2 :: ************************************************************* :: * Call your batch file* :: ************************************************************* CALL Drive:\path\to\batchfile.bat %REPOS% %REV%
batchfile.bat
@ECHO OFF
setlocal enabledelayedexpansion
:: take the path and revision from the post-commit hook and use svnlook to gather info
SET REPOS=%1
SET REV=%2
:: Get Repository name from REPOS path
for /f "tokens=1,2,3,4 delims=/ " %%a in ("%REPOS%") do SET REPOSNAME=%%c
:: Build the svnlook commands
SET INFOCMD=Drive:\path\to\subversion\bin\svnlook info -r %REV% %REPOS%
SET DIRCMD=Drive:\path\to\subversion\bin\svnlook dirs-changed -r %REV% %REPOS%
:: Get USR from Info line 1 and MSG from line 4
SET /a counter=1
FOR /f "usebackq delims=" %%a in (`%INFOCMD%`) DO (
if "!counter!"=="1" SET USR=%%a
if "!counter!"=="4" SET MSG=%%a
set /a counter+=1
)
:: Get folder from dirs-changed ... only need the first line
FOR /f usebackq %%a IN (`%DIRCMD%`) DO (
SET DIR=%%a
GOTO GetProject
)
:: Get project name from DIR ... it is the first folder
:GetProject
for /f "tokens=1 delims=/ " %%a in ("%DIR%") do SET PROJECT=%%a
:End
CALL twittercurl.bat "#%PROJECT% updated by #%USR% in the #%REPOSNAME% repsoitory. %MSG%"
The CALL to twittercurl.bat is described here: Microblogging for Applications
Please post any corrections and ideas!