Anonymous (owner)

Revisions

  • f57e65 Fri May 01 08:39:57 -0700 2009
  • db8a46 Fri May 01 08:39:14 -0700 2009
  • f375cd Fri May 01 08:24:49 -0700 2009
gist: 105083 Download_button fork
public
Public Clone URL: git://gist.github.com/105083.git
Embed All Files: show embed
post-commit.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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)