Ruby SVN Hooks

A domain specific language for implementing svn repository hooks in ruby.

The goal of this project is to allow developers or sysadmins an easier method for responding to svn hook events. The default behavior of subversion is to call an executable script based on the type of event that’s occurred. For places where multiple projects may exist under a single repository, this becomes a bit complicated since it’s probably desirable to respond differently depending on what project has been modified by a commit.

Important: This package is still in early stages of development. Everything you read here is subject to change until version 1.0.0.

Installation:

You can download the gem from RubyForge or just install using the ruby gems command line:

sudo gem install svn_hooks

Once installed, you’ll need to run the setup script on your svn repository (on the server side):

svn_rubyhooks /path/to/my/repository

This will do a couple things. First, it will create all of the callback files that are expected by svn in the hooks directory. If there are existing scripts, they will be moved out of the way by appending their filenames with .old. Next, it will create a scripts directory within the hooks directory.

Usage:

When any event happens to the repository that will trigger one of the event scripts, every script in the hooks/scripts directory with a .rb extension will be executed. Within these scripts, you can use the following filters for deciding how and when your code is executed.

Path Based Filtering

Code within this block will only be executed if files within the specified path or paths have been modified.

for_path 'repo/projects/my_project/trunk/*' do
  #... event handler here
end

Event Based Filtering

Code within this block will only be executed in response to a specific svn event.

for_event 'post-commit' do
  #... event handler here
end

Nested Filters

The preferred method is to filter on both event and path

for_event 'post-commit' do
  for_path 'repo/projects/my_project/trunk/*' do
    #... event handler here
  end
end

Event Details

All filter blocks can optionally receive as SVN::Stat object, which can provide many details about the event.

for_event 'post-commit' do |details|
  puts details.revision
  puts details.event
  puts details.author
  puts details.date
  puts details.files
end

One Response to “Ruby SVN Hooks”

  1. The Blog that Noone Reads » Blog Archive » Keeping and Eye on SVN with svn_hooks Says:

    [...] I’ve been working on a new ruby gem to make it easier to write scripts for handling subversion events. The idea is to allow you to separate your code into files based on project or task, rather than based on event. There are some simple methods available for filtering based on event type or area of the repository that’s been touched. Also made available are all of the details of the last event, including touched files (and their state flags), author, date, and comment. You can get the package here. [...]

Leave a Reply