# Created by Damian Nicholson
# Product Manager
# hedgehoglab
# damian.nicholson@hedgehoglab.com
#
# NOTE: THIS SCRIPT IT TAILORED TO WORKING WITH SUBVERSION AND FIXX VERSION 1.7
# More specific instructions can be found at http://gist.github.com/102437
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'cgi'
require 'yaml'
GIT = `which git`.strip
REVISION = `#{GIT} log -1 | sed -e 's/commit //' -e '2,$d'`.chomp
DETAILS = {
:path => '0.0.0.0',
:port => 8080
}
def gitCommitTofixx(revision, details)
commit_author = `#{GIT} show --pretty=format:"%an" #{revision} | sed q`.chomp
commit_message = `#{GIT} show --pretty=format:"%s" #{revision} | sed q`.chomp
commit_date = `#{GIT} show --pretty=format:"%aD" #{revision} | sed q`.chomp
commit_changed = `#{GIT} diff-tree -r --name-status #{revision} | sed -n '$p'`
# Regex to search for #issueId
regex = /#\d+/
# Scans the commit message for #issueId tag
issue_id = commit_message.scan(regex)
if !issue_id.empty?
Net::HTTP.start(details[:path], details[:port]) { |http|
commit_changes = commit_changed.split("\n").inject([]) { |memo, line| memo << [$1, $2] if line.strip =~ /(\w)\s+(.*)/ }.to_yaml
# Strips the hash tag
stripped_issue = issue_id.to_s.delete('#').to_i
req = Net::HTTP::Post.new("/api/issues/#{stripped_issue}/comments")
req.basic_auth "username", "password"
req.set_content_type('application/xml')
# Creating the xml to be posted to fixx
xml = <<-END_XML
<comment>
<text>
Commited by: #{CGI.escapeHTML(commit_author)} \n
Commit message: #{CGI.escapeHTML(commit_message.gsub!(regex, ''))} \n
Files changed: \n #{commit_changes}
</text>
<createdAt>#{DateTime.now.to_s}</createdAt>
</comment>
END_XML
req.body = xml.strip
res = http.request(req)
if res.is_a? Net::HTTPSuccess
# OK
else
return false
end
}
end
end
gitCommitTofixx(REVISION, DETAILS)