#!/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 = "
Revision: #{revision}
Author: #{user}
Date: #{date}


" message += "
Log Message: #{CGI.unescapeElement(log, 'br')}


" message += "
Modified Path(s):
#{changed}


" count = 0 diff.each do |top_line| top_line.split("\n").each do |line| count +=1; color = case when line =~ /^\+\+\+ / || line =~ /^--- /: "#FFDD88" when line =~ /^Modified: / || line =~ /^=+$/ || line =~ /^@@ /: "#FFDD88" when line =~ /^-/: "#FF8888" when line =~ /^\+/: "#BBFFBB" else "#FFFFFF" end modified = "" if line =~ /^Modified: / modified = true mod_div_border = "border:1px solid black; margin-bottom: 15px;padding:2px;" mod_div_end = "" and count =1 unless count == 1 mod_div = "
" if count == 1 end if line =~ /^\+\+\+/ || line =~ /^---/ || line =~ /^Modified: / || line =~ /^=+$/ || line =~ /^@@ / font = "font-weight: bold;" end if line =~ /^Added: / line = "" end if line =~ /^Property changes on: / mod_div_end = "
" and count =1 unless count == 1 mod_div_border = "border:1px solid black; margin-bottom: 15px;" mod_div = "
" if count == 1 color = "#FFCCFF" end if line =~ /^Name: / || line =~ /^ \+/ || line =~ /^___/ line = "" end message << %Q{#{mod_div_end}#{mod_div}
#{CGI.escapeHTML(line)}
} end end message += "
" Mailer.deliver_message(recipients, from_user, subject, message)