Integrating Subversion into Basecamp and Campfire

October 5th, 2007 by Joel

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!

Improve your email productivity

January 25th, 2007 by Joel

Ryan Carson just posted a small tip on his blog about how he improved his email productivity using TextExpander for the Mac.

Using a mix of keywords and/or keyboard shortcuts, TextExpander slashes the time it takes to write an email, especially if it contains lots of content that you repeatedly use. Perfect for writing support emails.

I didn’t need to look for for a Windows alternative. The QuickText extension for Thunderbird does exactly the same thing. Just define your shortcut, along with its own keyboard shortcut and keyword. Then write your email - very quickly!

Another genius product!

Bye DOS windows, hello Powershell

November 17th, 2006 by Joel

One of the worst thing I ever have to do while developing on Windows, is to use the windows DOS command window. It has to be one of the most unfriendly pieces of software of the planet. So when I heard that MS had just released version 1.0 of an all new shell command window for Windows entitled PowerShell, I quickly installed it and oh how I love it!

Windows PowerShell

Getting Real: The smarter, faster, easier way to build a successful web application

March 2nd, 2006 by Joel

The guys over at 37Signals really are doing something right. Not content with launching a masively popular open-source web application framework, aswell as five of the web’s most popular Web2.0 applications; they have now decided to let us all in on the act and have written a book on how they do it.

Getting Real: The smarter, faster, easier way to build a successful web application; is a 171 page PDF book, detailing “the business, design, programming, and marketing principles of 37signals. The book is packed with keep-it-simple insights, contrarian points of view, and unconventional approaches to software design. This is not a technical book or a design tutorial, it’s a book of ideas.”

So who am I to knock the in crowd away! I’m about to buy a copy. Keep it here for a review and evidence that your $19 well earned dollars will be put to good use.