tag:help.lighthouseapp.com,2008-09-20:/discussions/tips-tricks/6-svn-beacon-1-repository-multiple-lh-projectsLighthouse: Discussion 2011-04-07T05:34:21Ztag:help.lighthouseapp.com,2008-09-20:Comment/101712007-05-28T00:05:44Z2009-06-20T20:56:49ZSVN Beacon: 1 repository, multiple LH Projects<div><p>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</p>
<pre>
<code>
ping_lighthouse :token => 'DEFAULT TOKEN', :users => { 'bob' => 'BOBS TOKEN' } do |config|
config[/^trunk/] = {
:account => 'http://activereload.lighthouseapp.com',
:project => 2, # REPLACE
}
end</code>
</pre>
<p>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 :)</p></div>Ricktag:help.lighthouseapp.com,2008-09-20:Comment/101712007-05-28T17:32:42Z2009-06-20T20:56:49ZSVN Beacon: 1 repository, multiple LH Projects<div><p>aww it doesn't :-(</p>
<p>Still trying to figure out why, but when run from the command
line like this:</p>
<pre>
[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
</pre>
<p>.. it returns the error above and the log file looks like:</p>
<pre>
repo:/home/svn_joergbattermann.com/repos/ rev: 24
Error: undefined local variable or method
</pre>
<p>.. too.</p>
<p>the whole post-commit-file looks like this now:</p>
<pre>
#!/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 = <
#{CGI.escapeHTML("%s committed changeset [%d]" % [commit_author, revision])}
#{CGI.escapeHTML(commit_log)}
#{CGI.escapeHTML(commit_changes)}
#{CGI.escapeHTML(revision.to_s)}
#{CGI.escapeHTML(commit_date.split('(').first.strip)}
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
</pre></div>Joerg Battermanntag:help.lighthouseapp.com,2008-09-20:Comment/101712007-05-28T17:48:38Z2009-06-20T20:56:49ZSVN Beacon: 1 repository, multiple LH Projects<div><p>Doh, see this is why I didn't want to post the code. I hadn't
actually ran it yet :)</p>
<p>Above the 'commit = {}' line at the top of the #ping_lighthouse
declaration add:</p>
<pre>
<code>
repo_path = ARGV[0]
revision = ARGV[1]</code>
</pre></div>Ricktag:help.lighthouseapp.com,2008-09-20:Comment/101712007-05-28T18:37:51Z2009-06-20T20:56:49ZSVN Beacon: 1 repository, multiple LH Projects<div><p>Yay - it's working!</p>
<p>(manually - now I just gotta check why the post-commit hook is
not being called by svnserve)</p></div>Joerg Battermanntag:help.lighthouseapp.com,2008-09-20:Comment/101712007-05-28T19:36:04Z2009-06-20T20:56:49ZSVN Beacon: 1 repository, multiple LH Projects<div><p>Cool, thanks for being the guinea pig!</p></div>Rick