Integrating Subversion into Basecamp and Campfire

October 5th, 2007 at 6:38 pm by Joel in Productivity, Ruby

For the last few days, I have been thinking about how me and the team around me can improve productivity and communications when developing. Currently, the system we use is a little disjointed, and utilizes several different systems and solutions. Fortunately one such solution is Basecamp, which happens to be one of the best around and has been in use by the company for a while now. So after spending a little time with the web based application, I realised that it should be able to do, or at least manage everything we do.

So last night I sat down and played with the Basecamp API, to see what could be done with it. And I came up with a post-commit hook for Subversion, that posts a message for each subversion commit. This message tells me the change log, what files were changed, and who made the commit. So now we can all see and receive Basecamp notices for every single changeset.

We have also started using Campfire, so I then had a little play with Tinder; Campfire’s unofficial API, and added some more code to the Subversion hook. So as well as creating a message in Basecamp detailing each Changeset, the same changeset is also posted in the appropriate Campfire room. So we have a real time view of our development progress.

So here is the code. It’s all in Ruby, as it was easy peasy. And it utilises the Basecamp API Wrapper.

  1. %w( rubygems tinder basecamp ).each { |f| require f }
  2.  
  3. config = {
  4. :subdomain => 'My-Subdomain', # Campfire and Basecamp subdomain
  5. :email => 'user@mydomain.com', # Campfire email login
  6. :username => 'username', # Basecamp username
  7. :pass => 'password',
  8. :room => 'Development', # Campfire room
  9. :project_id => 12345, # Basecamp project id
  10. :category_id => 678910, # Basecamp message category ID
  11. :ssl => true
  12. }
  13.  
  14. svnlook = '/usr/bin/svnlook' # full path to the svnlook command
  15. repo_path = ARGV[0]
  16. revision = ARGV[1]
  17. project = repo_path.split('/').last
  18.  
  19. commit_author = `#{svnlook} author #{repo_path} -r #{revision}`.chop
  20. commit_log = `#{svnlook} log #{repo_path} -r #{revision}`
  21. commit_files = `#{svnlook} changed #{repo_path} -r #{revision}`
  22.  
  23. # create a message in basecamp
  24. basecamp = Basecamp.new("#{config[:subdomain]}.projectpath.com", config[:username], config[:pass], true)
  25. basecamp.post_message config[:project_id], {
  26. :title => "Changeset ##{revision}",
  27. :body => "#{commit_author} just committed changeset ##{revision}…\n\n<blockquote><pre>#{commit_log}\n#{commit_files}</pre></blockquote>",
  28. :category_id => config[:category_id]
  29. }
  30.  
  31. # create a message in campfire
  32. campfire = Tinder::Campfire.new(config[:subdomain], :ssl => config[:ssl])
  33. campfire.login config[:email], config[:pass]
  34. room = campfire.find_room_by_name config[:room]
  35. room.speak "#{commit_author} just committed changeset ##{revision}…"
  36. room.paste "#{commit_log}\n#{commit_files}"
  37. </code>

Simply copy and paste this into a file called ‘post-commit.rb’ and save that in your subversion repository’s hooks directory. Don’t forget to set its permissions as required (chmod 755 on linux/unix). Then create another file in your hooks directory and call it ‘post-commit’ and do the same with the permissions. In the ‘post-commit’ file, paste the following code:

#!/bin/sh
  1.  
  2. REPOS="$1"
  3. REV="$2"
  4.  
  5. ruby /Users/joelmoss/dev/src/testing/hooks/campfire.rb "$REPOS" "$REV"
  6. </code>

If ‘post-commit’ already exists, just append the last line above to the end of the file.

You will then need to install a few Ruby Gems. Namely Tinder and XML-Simple. So just run the following command:

sudo gem install tinder xml-simple --include-dependencies

And finally, you will need the Basecamp API wrapper. You can get that at http://www.basecamphq.com/api/basecamp.rb. Save that in somewhere in your Ruby path. Ideally, that would be in your ’siteruby’ directly. On my Mac, that is at ‘/usr/local/lib/ruby/siteruby/1.8/’.

And now you should be good to go. As long as you have enabled the API in your Basecamp and your settings are correct, whenever anyone makes a commit to Subversion, you will all be able to see it in Basecamp and Campfire.

I plan to do more with this, as we will need a better bug management system, as Bugzilla is just so damn ugly. But I will leave that to another post.

Enjoy!

 

2 Comments

[...] guys at collectiveidea came up with an interesting way of writing Campfire plugins for things like post_commit VCS hooks. It’s called Tinder. [...]

[...] guys at collectiveidea came up with an interesting way of writing Campfire plugins for things like post_commit VCS hooks. It’s called Tinder. Enjoy! ShareThis This entry was written by Sean Murphy, posted on June [...]

 

Leave your Comments

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>