Friday, February 19, 2010

Sending post commit emails from Subversion running on windows

Creating a hook in Subversion running on a Linux server it seems to be straight forward. When creating a hook on a Windows server the process is fairly straight foward as well but there are a couple of gotchas.

1. Make sure to set the environmental variables that you need or provide the full path for everything that you need because Subversion does not provide environmental variables.
2. Since the post-commit.cmd or post-commit.bat script is executed as a batch file in windows it is a lot more limited that a perl script in Linux. It is best to hand off the real work to powershell right away.

Create a file in the hooks folder of your repository and name it post-commit.cmd or post-commit.bat.

POST-COMMIT.cmd
SET REPOS=%1 SET REV=%2
SET SITENAME=name of you repository
SET SMTP_SERVER=server address
SET EMAIL_TO=email@domain.com,email@domain.com,email@domain.com
SET EMAIL_FROM=email@domain.com

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe PATHTOFILE\emailer.ps1 '%SMTP_SERVER%' '%EMAIL_TO%' '%EMAIL_FROM%' '%SITENAME%' '%REPOS%' '%REV%'

emailer.ps1

# Sends an email message to the configured addresses, notifying # of changes to the current repository
#

$server = $args[0]

$to = $args[1]
$from = $args[2]
$sitename = $args[3]
$svn_repos = $args[4]
$svn_rev = $args[5]
$subject = ""
$body = ""

echo $svn_repos

$author = &"C:\Program Files\VisualSVN Server\bin\svnlook.exe" author $svn_repos --revision $svn_rev

$subject= "SVN New Revision Committed By: ($author) To: $sitename Revision Number: ($svn_rev)"

$body+="Comments for this Revision: `n"

foreach($svnlook_log_line in &"C:\Program Files\VisualSVN Server\bin\svnlook.exe" log $svn_repos --revision $svn_rev)

{
if($svnlook_log_line -ne "")
{
$body+=$svnlook_log_line + "`n"
}
}

if ($body-ne "")

{
$body+= "`n`n"
}

$body+="Files Changed in this Revision `n"

foreach($svnlook_changed_line in &"C:\Program Files\VisualSVN Server\bin\svnlook.exe" changed $svn_repos --revision $svn_rev)

{
$body+= $svnlook_changed_line + "`n"
}

$mailer = new-object Net.Mail.SMTPclient($server)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$mailer.send($msg)

Installing the Plugin to generate default rules in CslaGenerator

Download the rar file that contains the Visual Studio solution CslaGenTestPlugin from here:

Use 7 zip or some other program that can handle rar files to extract the rar file.

Open the CslaGenTestPlugin.sln solution.

Add a reference to CslaGenerator.exe, DBSchemaInfo.dll and WeifenLuo.WinFormsUI.Docking.dll

Build the solution and copy the CslaGenTestPlugin.dll, CslaGenTestPlugin.pdb, and CslaGenTestPlugin.xml files that you just built to the CslaGenerator\Plugins directory.

Once you start CslaGenerator the "Create Default Rules" menuitem will be available under the "Plugins" menu. Just select that menuitem to create default rules for all of your editable objects.