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
72
73
|
# File 'lib/git-trello.rb', line 26
def post_receive
while msg = gets
old_sha, new_sha, ref = msg.split(' ', 3)
commit = @repo.commit(new_sha)
match = commit.message.match(/((case|card|close|fix)e?s? \D?([0-9]+))/i)
next unless match and match[3].to_i > 0
puts "Trello: Commenting on the card ##{match[3].to_i}"
results = @http.get_card(@board_id, match[3].to_i)
unless results
puts "Trello: Cannot find card matching ID #{match[3]}"
next
end
results = JSON.parse(results)
target_list_id = ""
target_list_id = case match[2].downcase
when "case", "card" then @list_id_in_progress
when "close", "fix" then @list_id_done
end
puts "Trello: Moving card ##{match[3].to_i} to list #{target_list_id}"
message = "#{commit.author.name}:\n#{commit.message}"
message << "\n\n#{@commit_url_prefix}#{new_sha}" unless @commit_url_prefix.nil?
message.gsub!(match[1], "")
message.gsub!(/\(\)$/, "")
message.gsub!(/Signed-off-by: (.*) <(.*)>/,"")
@http.(results["id"], message)
unless target_list_id == ""
to_update = {}
unless results["idList"] == target_list_id
to_update[:idList] = target_list_id
@http.update_card(results["id"], to_update)
end
end
""
end
end
|