Subversion commit email notification script
find more posts in: ruby, subversionSo I’ve been using Subversion on a Linux box for a while now to manage my code for various freelance and personal projects. I’ve recently started working with some other people who need access to the server, and I wanted to receive emails when they make a commit. I also didn’t want to deal with svnnotify (um, or I possibly didn’t know about it until it was too late). Luckily Subversion makes it very easy to write a post-commit script to do this. Here’s the ruby script I ended up with:
#!/usr/bin/ruby require 'rubygems' require 'action_mailer' class SimpleMailer < ActionMailer::Base def simple_message(to, sub, message) from 'walrus svn <svn@wlrs.net>' recipients to.join(", ") subject sub body message end end path = ARGV[0] revision = ARGV[1] 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} -r #{revision}`.chomp dirs = `/usr/bin/svnlook dirs-changed #{path} -r #{revision}`.chomp date = `/usr/bin/svnlook date #{path} -r #{revision}`.chomp dir_list = dirs.split("\n").collect do |dir| dir =~ /([^\/]+)/ $1 end dir_list.uniq! recipients = ["joey@wlrs.net"] #other people might want these emails recipients << "team@mycompany.com" if dir_list.include?("mycompany.com") recipients << "someone.else@oursite.com" if dir_list.include?("oursite.com") subject_log = log.split("\n")[0].slice(0..60) dir_string = dir_list.join(", ") subject = "r#{revision} #{user} in #{dir_string}: \"#{subject_log}\"" message = "#{user} committed these changes on #{date}:\n\n#{log}\n\n#{changed}\n\n#{diff}" ActionMailer::Base.smtp_settings = { :address => 'localhost', :port => 25, :domain => 'localdomain'} SimpleMailer.deliver_simple_message(recipients, subject, message)
Projects in my repository are setup like this:
svn/oursite.com/trunk svn/mycompany.com/trunk
That means we just look at the svn directory to see which project is being modified, then we alert the appropriate people. The emails are plain text and include the commit comments, modified files, and a full diff of the commit. What else do you need?
- art
- audio
- baseball
- bikes
- books
- browsers
- complaints
- crime
- death
- dumb things
- energy
- environment
- family
- friends
- gadgets
- internet
- life
- los angeles
- marriage
- movies
- music
- mysql
- new york
- os x
- pasadena
- photos
- php
- plugins
- podcasting
- politics
- portland
- pugs
- rss
- ruby
- splideo
- subversion
- ubuntu
- video
- watir
- wordpress
- work
No Responses
Please Wait
Leave a Reply