SVN Beacon: 1 repository, multiple LH Projects

Joerg Battermann's Avatar

Joerg Battermann

27 May, 2007 07:57 PM

Hello there,

one question - I have one 'bit' repository which holds all my projects in one place, even though they all have seperate projects in my lighthouse account.

Is it possible to have the proper changesets added to the corresponding projects in lh with just one post-commit hook for that repository?


  1. 1 Posted by Rick on 28 May, 2007 12:05 AM

    Rick's Avatar

    Sure, it's up to your script to figure out which project to send it to though. I've been hacking on the svn beacon example to try and come up with a better solution for it:

      ping_lighthouse :token => 'DEFAULT TOKEN', :users => { 'bob' => 'BOBS TOKEN' } do |config|
        config[/^trunk/] = { 
          :account => '',
          :project => 2, # REPLACE

    The yielded config object is a hash where each key should be a regular expression that matches against the change paths, and the value should be a hash of options for the match. I haven't actually set this up just yet, but it looks like it should work :)

  2. 2 Posted by Joerg Batterman... on 28 May, 2007 05:32 PM

    Joerg Battermann's Avatar

    aww it doesn't :-(

    Still trying to figure out why, but when run from the command line like this:

    [z12912AA:/home/] admin$ /opt/csw/bin/ruby /home/ /home/ 24
    sh: repo_path for main:Object trace:": not found

    .. it returns the error above and the log file looks like:

    repo:/home/ rev: 24
    Error: undefined local variable or method

    .. too.

    the whole post-commit-file looks like this now:

    require 'yaml'
    require 'cgi'
    # configure multiple project settings below
    def ping_lighthouse(options = {})
      config = {}
      yield config if block_given?
      commit_dirs_changed = `#{SVNLOOK} dirs-changed #{repo_path} -r #{revision}`
      config.each do |prefix, prefix_options|
        if commit_dirs_changed.split(/\n/)[0] =~ prefix
      return unless options[:account] && options[:project] && options[:token]
      repo_path      = ARGV[0]
      revision       = ARGV[1]
      commit_author  = `#{SVNLOOK} author #{repo_path} -r #{revision}`.chop
      commit_log     = `#{SVNLOOK} log #{repo_path} -r #{revision}`
      commit_date    = `#{SVNLOOK} date #{repo_path} -r #{revision}`
      commit_changed = `#{SVNLOOK} changed #{repo_path} -r #{revision}`
      commit_changes = commit_changed.split("\n").inject([]) do |memo, line| 
        if line.strip =~ /(\w)\s+(.*)/
          memo << [$1, $2]
      changeset_xml = <
        #{CGI.escapeHTML("%s committed changeset [%d]" % [commit_author, revision])}
      token = options[:users][commit_author] || options[:token]
      url   = '%s/projects/%d/changesets.xml?_token=%s' % [options[:account], options[:project], token]
      cmd   = "#{CURL} -H 'Accept: application/xml' -H 'Content-Type: application/xml' -d '#{changeset_xml.gsub(/'/, "\\'").strip}' #{url}"
      SVNLOOK    = '/opt/csw/bin/svnlook'
      CURL       = '/opt/csw/bin/curl'
      LOG_FILE   = '/tmp/svn-hooks.log'
      ping_lighthouse :token => 'mytoken', :users => { 'Joerg Battermann' => 'beacon_name' } do |config|
        config[/^subrepos1\/trunk/] = { 
            :account => '',
            :project => 1234, # REPLACE
        config[/^subrepos2\/trunk/] = { 
        :account => '',
        :project => 1235, # REPLACE
      %x{echo "repo:#{ARGV[0]} rev: #{ARGV[1]}" > #{LOG_FILE}}
      %x{echo "Error: #{$!} trace:#{caller}" >> #{LOG_FILE}}
  3. 3 Posted by Rick on 28 May, 2007 05:48 PM

    Rick's Avatar

    Doh, see this is why I didn't want to post the code. I hadn't actually ran it yet :)

    Above the 'commit = {}' line at the top of the #ping_lighthouse declaration add:

    repo_path = ARGV[0]
    revision = ARGV[1]
  4. 4 Posted by Joerg Batterman... on 28 May, 2007 06:37 PM

    Joerg Battermann's Avatar

    Yay - it's working!

    (manually - now I just gotta check why the post-commit hook is not being called by svnserve)

  5. 5 Posted by Rick on 28 May, 2007 07:36 PM

    Rick's Avatar

    Cool, thanks for being the guinea pig!

Discussions are closed to public comments.
If you need help with Lighthouse please start a new discussion.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac