SVN Beacon: 1 repository, multiple LH Projects

Subscribe to SVN Beacon: 1 repository, multiple LH Projects 6 post(s), 2 voice(s)

 
Avatar Joerg Batter... 5 post(s)

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?

-J

 
Avatar rick Administator 546 post(s)

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: http://pastie.caboo.se/65167


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

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 :)

 
Avatar Joerg Batter... 5 post(s)

aww it doesn’t :-(

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

[z12912AA:/home/svn_justbe.com/repos/hooks] admin$ /opt/csw/bin/ruby /home/svn_joergbattermann.com/repos/hooks/post-commit /home/svn_joergbattermann.com/repos/ 24
sh: repo_path for main:Object trace:": not found

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

repo:/home/svn_joergbattermann.com/repos/ rev: 24
Error: undefined local variable or method

.. too.

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

#!/opt/csw/bin/ruby
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
      options.update(prefix_options)
    end
  end

  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]
    end
  end.to_yaml

  changeset_xml = <<-END_XML
  <changeset>
    <title>#{CGI.escapeHTML("%s committed changeset [%d]" % [commit_author, revision])}</title>
    <body>#{CGI.escapeHTML(commit_log)}</body>
    <changes>#{CGI.escapeHTML(commit_changes)}</changes>
    <revision>#{CGI.escapeHTML(revision.to_s)}</revision>
    <changed-at type="datetime">#{CGI.escapeHTML(commit_date.split('(').first.strip)}</changed-at>
  </changeset>
END_XML

  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}" 
  %x{#{cmd}}
end

begin
  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 => 'http://myurl.lighthouseapp.com',
        :project => 1234, # REPLACE
    }
    config[/^subrepos2\/trunk/] = { 
    :account => 'http://myurl.lighthouseapp.com',
    :project => 1235, # REPLACE
    }
  end
rescue
  %x{echo "repo:#{ARGV[0]} rev: #{ARGV[1]}" > #{LOG_FILE}}
  %x{echo "Error: #{$!} trace:#{caller}" >> #{LOG_FILE}}
end
 
Avatar rick Administator 546 post(s)

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]
 
Avatar Joerg Batter... 5 post(s)

Yay – it’s working!

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

 
Avatar rick Administator 546 post(s)

Cool, thanks for being the guinea pig!