Tuesday, March 24, 2009

Connecting svn checkins to Campfire (under Windows)

We use campfire for office communications, and wanted hear from subversion (our source control repository) whenever a checkin happens. There's a great article by David Naffis at Intridea describing just how to do this, but unfortunately their solution is aimed at linux.

To get the same magic to happen on Windows:
  1. Install ruby if you don't already have it. Instant Rails is a fairly easy install.
    (i) Download version 2.0, or look here for the latest build.
    (ii) Unzip that download wherever you want it to live - I chose C:\InstantRails-2.0-win because that was the default name. (Note that Instant Rails doesn't like spaces in their file names.)
    (iii) After you download it, run InstantRails.exe from the root of the package. (On my system, this was C:\InstantRails-2.0-win\InstantRails.exe.) This configures all of the instant rails package, including some stuff we don't need, like apache and mysql.

  2. Install Tinder.
    (i) I downloaded tinder-1.2.0.gem from rubyforge - check for a more recent version here. I copied the gem file into C:\InstantRails-2.0-win
    (ii) Open up a command prompt. (Start|Run|cmd)
    (iii) Switch to the InstantRails directory. (CD C:\InstantRails-2.0-win)
    (iv) Run "use-ruby.cmd". This will add ruby to your path.
    (v) Run "gem install tinder-1.2.0.gem". This will take a little while.

  3. Create svn-campfire.rb as described in Intridea's post. I copied their text into C:\InstantRails-2.0-win\svn-campfire.rb, and then I removed their code at line 17 which read:
    project = ARGV[0].gsub("/home/user/svn/", '')
    and replaced it with
    project = '/svnrepos'
    This could also have been "project=ARGV[0]".
    I also replaced the login info with a local account and password, and replaced line 7 which read:
    campfire = Tinder::Campfire.new 'campfiresubdomain'
    campfire = Tinder::Campfire.new( 'campfiresubdomain', :ssl => true)

  4. I tested svn-campfire.rb by running
    C:\InstantRails-2.0-win\ruby\bin\ruby C:\InstantRails-2.0-win\svn-campfire.rb /svnrepos 1000
    (Where svnrepos is the name we use for our svn repository, and 1000 was a random checkin number.) There may be some debugging required here - especially if you mess up the login information in the svn-campfire.sb. Have fun!

  5. I then added
    C:\InstantRails-2.0-win\ruby\bin\ruby C:\InstantRails-2.0-win\svn-campfire.rb "%0" "%1"
    to the post-commit.bat file in C:\svnrepos\hooks\post-commit.bat. (Your batch file will probably be found elsewhere, so figure it out;) If you don't have a post-commit.bat file, then you will create one. (Note that the %0, %1 parameters are different here than on linux, which would use $0, $1.)
And that's all it took.

(In this author's opinion, this installation process is a nightmare, and should be easier. But on the plus side, at least you can do it. Thanks for the helpful article, David)

No comments:

Post a Comment