Skip to content

Instantly share code, notes, and snippets.

@ybakos
Created August 29, 2009 17:40
Show Gist options
  • Select an option

  • Save ybakos/177601 to your computer and use it in GitHub Desktop.

Select an option

Save ybakos/177601 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'yaml'
require 'cgi'
SVNLOOK = '/usr/bin/svnlook'
CURL = '/usr/bin/curl'
LOG_FILE = '/tmp/svn-hooks.log'
# Configuration
# Set your basecamp url, username, password and project id here.
@basecamp_url = "http://BASECAMP URL"
@basecamp_username = "USERNAME"
@basecamp_password = "PASSWORD"
@basecamp_project = "PROJECT ID"
@basecamp_project_category = "CATEGORY ID"
def svn_images(commit_log)
commit_log.gsub(/^A\s+/, '<img src="http://noona.se/basecamp/add.png" alt="Added" /> ').
gsub(/^D\s+/, '<img src="http://noona.se/basecamp/delete.png" alt="Deleted" /> ').
gsub(/^U\s+/, '<img src="http://noona.se/basecamp/update.png" alt="Updated" /> ').
gsub(/---/, "")
end
def gather_and_post(repo_path, revision)
commit_author = `#{SVNLOOK} author #{repo_path} -r #{revision}`.chop
commit_log = `#{SVNLOOK} log #{repo_path} -r #{revision}`.strip
commit_date = `#{SVNLOOK} date #{repo_path} -r #{revision}`
commit_changes = `#{SVNLOOK} changed #{repo_path} -r #{revision}`.strip
changeset_xml = <<-END_XML
<request>
<post>
<category-id>#{@basecamp_project_category}</category-id>
<title>#{CGI.escapeHTML("%s committed changeset [%d]" % [commit_author, revision])}</title>
<body>
#{CGI.escapeHTML(commit_log)}
</body>
<extended-body>
#{CGI.escapeHTML(svn_images(commit_changes))}
</extended-body>
<use-textile>1</use-textile>
</post>
</request>
END_XML
url = "#{@basecamp_url}/projects/#{@basecamp_project}/msg/create"
cmd = "#{CURL} -H 'Accept: application/xml' -H 'Content-Type: application/xml' -u #{@basecamp_username}:#{@basecamp_password} -d '#{changeset_xml.gsub(/'/, "\\'").strip}' #{url}"
%x{#{cmd}}
end
begin
gather_and_post ARGV[0], ARGV[1]
rescue
%x{echo "repo:#{ARGV[0]} rev: #{ARGV[1]}" > #{LOG_FILE}}
%x{echo "Error: #{$!} trace:#{caller}" >> #{LOG_FILE}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment