#!/usr/bin/ruby
##########################################################################
# This is a ruby script which can be configured with svn post-commit Hook.
# Once configured, it will send commit notification by email, which will
# contain log message, files added/updated and svn diff.
#
#
# This script is written by Akhil Bansal(http://webonrails.com)
# It worked fine for me. Use this script at your own risk, if
# your computer explode, it will not be my fault ;-)
#
##########################################################################
require 'rubygems'
require 'action_mailer'
require 'cgi'
# You can edit below
#
#
# Subject prefix
sub = "[test_project@vinsol]" # A project 'test_project' is maitained at vinsol
#list of users who will recieve commit notification
recipients = ["bansalakhil30.10@gmail.com", "akhil@vinsol.com"]
# email which will appear in from email field
from_user = "svn-notify@somedomain.com"
# your smtp settings here
ActionMailer::Base.smtp_settings = { :address => 'localhost', :port => 25, :domain => 'domain.com'}
# Do not edit below this line
path = ARGV[0]
revision = ARGV[1]
class Mailer < ActionMailer::Base
def message(to, from_user, sub, message)
from from_user
recipients to.join(", ")
subject sub
body message
content_type "text/html"
end
end
user = `/usr/bin/svnlook author #{path} -r #{revision}`.chomp
log = `/usr/bin/svnlook log #{path} -r #{revision}`.chomp
changed = `/usr/bin/svnlook changed #{path} -r #{revision}`.chomp
diff = `/usr/bin/svnlook diff #{path} --no-diff-deleted --no-diff-added -r #{revision}`.chomp
dirs = `/usr/bin/svnlook dirs-changed #{path} -r #{revision}`.chomp
date = `/usr/bin/svnlook date #{path} -r #{revision}`.chomp
date = Time.parse(date).getutc + (5.5 * 3600)
date = date.strftime("%A %b %d,%Y %I:%M %p")
dir_list = dirs.split("\n").collect do |dir|
dir =~ /([^\/]+)/
$1
end
dir_list.uniq!
subject_log = log.slice(0..100) + "..."
dir_string = dir_list.join(", ")
subject = "#{sub} #{user}: \"#{subject_log}\" (Revision:#{revision} )"
changed = changed.gsub(/\n/, '
')
log = log.gsub(/\n/, '
')
message = "