Back to Blog

Get in Touch

Campfire SVN and email notification

By Dave Naffis October 5, 2007 in rails, ruby, campfire, subversion, svn

Missing

Here's a quick way to add Subversion notification for Campfire using Tinder.

Create svn-campfire.rb with the correct username and password:

#!/usr/local/bin/ruby
require 'rubygems'
require 'tinder'

svnlook = "/usr/local/bin/svnlook"


campfire = Tinder::Campfire.new 'campfiresubdomain'
campfire.login 'user@example.com', 'password'
room = campfire.find_room_by_name('room name')
room.join

if ARGV.size > 1
  revision = ARGV[1]
  path = ARGV[0]
  # we're using this for multiple svn repos so parse the project name from the path
  project = ARGV[0].gsub("/home/user/svn/", '')
  
  author = `#{svnlook} author -r #{revision} #{path}`
  paths  = `#{svnlook} changed -r #{revision} #{path}`   
  log    = `#{svnlook} log -r #{revision} #{path}`
  message = [log,paths].join("\n").strip
  url = "Changeset \##{revision} by #{author} (http://trac.domain.com/trac/#{project}/changeset/#{revision})"

  room.speak(url)
  room.paste(message)
else
  room.speak(ARGV[0])
end

room.leave

Add this to your SVN post-commit hook:

/usr/local/bin/ruby /path/to/svn-campfire.rb "$1" "$2"

Here's a quick way to send emails to campfire. Create an email address to use for sending messages to campfire and then create mailer-campfire.rb with your domain, usernames and passwords:

#!/usr/local/bin/ruby
require 'rubygems'
require 'action_mailer'
require 'tinder'
require 'net/pop'

# setup an email address to use for campfire
Net::POP3.delete_all("domain.com", nil, "user+domain.com", "password") do |m|
  campfire = Tinder::Campfire.new 'campfiresubdomain'
  campfire.login 'user@example.com', 'password'
  room = campfire.find_room_by_name('room name')
  room.join

  begin
    message = TMail::Mail.parse(m.pop)
    
    subject = message.subject if message.subject
    sender = message.from.first if message.from
    body = message.body if message.body
    
    room.speak("I've received an email from #{sender} with the subject '#{subject}'")
    room.paste(body)                
  rescue Exception => e
  end        
    
  room.leave
end

Then create a cron job to fire this off every minute:

* * * * * /usr/local/bin/ruby /home/path/to/mailer-campfire.rb

We also use it to remind us of daily standups:

#!/usr/local/bin/ruby
require 'rubygems'
require 'tinder'

campfire = Tinder::Campfire.new 'campfiresubdomain'
campfire.login 'user@domain.com', 'password'
room = campfire.find_room_by_name('room name')
room.join
room.paste("Time for daily standup.\nWhat did you do yesterday? What are you doing today? Any roadblocks?")    
room.leave

Our cron job fires it off every weekday at 2pm.:

0 14 * * 1-5 /usr/local/bin/ruby /home/path/to/status-campfire.rb

Next step, create a Jabber gateway for Campfire using Tinder.

Medium

Dave Naffis

David is an entrepreneur and software developer with demonstrated experience in software services, product development, strategy, and operations. He is a co-founder of Intridea, an Inc 500 winning software development firm where he oversaw several successful product spinouts. Before starting Intridea, Dave ran his own Ruby on Rails consultancy and worked as a software engineer and architect at companies including AOL, Cisco, and McKinsey. He holds a masters in Systems Engineering from The University of Virginia, has contributed to a number of open-source projects, and has spoken at numerous regional and national conferences.

More posts by Dave Naffis

Dave Naffis

Four years ago, what started as a team of three people with a conviction t...

Dave Naffis

In this new blog series, Why Your Company Needs a Rails Development S...

Dave Naffis