SVN log parsing using PowerShell
This script can be useful when gathering SVN release changes that occurred since the last release. It connects to SVN server, gets logs from within date range (last build and date now). Logs are then filtered, cleaned (removed if no comments were added). Next, email message is sent based on the retrieved data. To be able to run the script, you need to configure it by setting-up your own svn server url, credentials, also please make sure you have enabled running ps scripts on your server.
Enjoy!
param ( [string]$Version = "2.12.0.2", [string]$SendEmailsTo = "test@test.com", [string]$SVNUser = "user", [string]$SVNPass = "pass", [string]$SVNbranchRoot = "https://svn.test.com/www/Branches/MyApp/2.12.0" ) #get svn logs for the current release Function GetSVNLogs($lastBuildDate_) { [string]$fromDate = $lastBuildDate_.ToString("yyyy-MM-dd"); [string]$toDate = (get-date).ToString("yyyy-MM-dd"); [string]$RevisionDates = "{$fromDate}:{$toDate}"; #add -v param for verbose 1$log = 1(&$svn log $SVNbranchRoot -r $RevisionDates --limit 500 --xml --username $SVNUser --password $SVNPass); $logObjects = $log.log.logentry | Foreach-Object { $logEntry = $_ $logEntry | Select-Object ` @{ Name = "Revision"; Expression = { [int]$logEntry.revision } }, @{ Name = "Author"; Expression = { $logEntry.author } }, @{ Name = "Date"; Expression = { if ( $NoFormat ) { [datetime]$logEntry.date } else { "{0:dd/MM/yyyy hh:mm:ss}" -f [datetime]$logEntry.date } } }, @{ Name = "Message"; Expression = { $logEntry.msg } } | Foreach-Object { $_ | where-object { ![string]::IsNullOrEmpty($logEntry.msg) } | Select-Object Author, Date, Message } } return $logObjects } #send email function Function SendEmail($SendEmailsTo_, $EmailSubject_, $changes_) { $emailFrom = "automation@test.com" $smtpserver="smtp.test.com" $smtp=new-object Net.Mail.SmtpClient($smtpServer) foreach ($email in $SendEmailsTo_.split(';')) { $smtp.Send($emailFrom, $email, $EmailSubject_, $changes_) } } #get svn logs since the last release $SVNChanges = GetSVNLogs $lastBuildDate $changes += "`r`n`r`n"; $changes += "SVN changes sice last release`r`n"; $changes += $SVNChanges | Format-Table -AutoSize | Out-String; $changes += "`r`n-------------------------------------------------------------------`r`n"; $changes += "This is automated email, please do reply directly!"; #send email $EmailSubject = "Release $Version changes"; SendEmail $SendEmailsTo $EmailSubject $changes;