Corey Trager of BugTracker.NET has sent this vbs script below which can be enhanced to integrate SVN and BugTracker. It grabs entries from SVN when files are committed and posts to the database that BugTracker.Net uses.
I didn’t want this code to be lost in comments and copied here with formatting.
Thanks very much Corey.
option explicit ' HOW TO USE THIS SCRIPT ' This script is a Subversion "post-commit hook". ' To execute this script first create a file in your repository hooks folder ' called "post-commit.bat". ' Put just one line in the .bat file which will point to this script. ' c:\somewhere\btnet_post_commit.vbs %1 %2 ' Put this script where the .bat file is pointing to, and then edit the ' lines below. ' Change this line so that it's the path to your Subversion\bin\svnlook.exe dim svnlook_path svnlook_path = """c:\program files\subversion\bin\svnlook""" ' Change the database connection string here. ' This is NOT the same as the one in web.config. Web.config is using ADO.NET. ' This one is using plain old ADO. dim connection_string connection_string = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=btnet; User ID=sa; Password=;" dim temp_file temp_file = "C:\temp\btnet_svntemp.txt"
' END OF THE PARTS YOU HAVE TO CHANGE. THE REST SHOULD BE OKdim repos dim rev repos = wscript.arguments(0) rev = wscript.arguments(1) ' repos = "c:\cit\svnrepos" for testing ' rev = 12 for testing dim shell set shell = WScript.Createobject("WScript.Shell") dim cmd dim results_object dim log_string dim changed_string ' run the svnlook log command cmd = svnlook_path & " log -r " & rev & " " & repos set results_object = shell.exec(cmd) log_string = results_object.stdout.readall ' run the svnlook changed command cmd = svnlook_path & " changed -r " & rev & " " & repos set results_object = shell.exec(cmd) changed_string = results_object.stdout.readall ' for debugging ' wscript.echo log_string ' wscript.echo changed_string ' look for the bugid as the first digits in the checkin comment dim re set re = new regexp re.pattern = "^[0-9]*" dim matches set matches = re.execute(log_string) dim bugid if matches.count > 0 then set bugid = matches(0) else ' no digits, nothing to do wscript.quit 0 end if ' at this point, we have a bugid dim conn set conn = createobject("adodb.connection") conn.open(connection_string) ' loop through the files, the output of the "changed" command dim lines lines = split(changed_string, vbcrlf) if ubound(lines) > 0 then dim i for i = 0 to ubound(lines) - 1 dim cols cols = split(lines(i), " ") if ubound(cols) = 1 then dim action dim file action = cols(0) file = cols(1) dim sql sql = "insert into bug_file_revisions " sql = sql & " (bfr_bug, bfr_revision, bfr_action, bfr_file, bfr_date) " sql = sql & " values ($bug, $rev, N'$act', N'$file', getdate())" sql = replace(sql,"$bug",bugid) sql = replace(sql,"$rev",rev) sql = replace(sql,"$act",action) sql = replace(sql,"$file",file) conn.execute(sql) end if next end if
