-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-receive
76 lines (60 loc) · 1.82 KB
/
pre-receive
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
72
73
74
75
#!/usr/bin/env ruby
require 'rubygems'
require 'grit'
require 'rest-client'
def extractTransactionIdFromCommit(commit)
transactionId = nil
commit.message.each_line do |line|
if line.start_with? "Transaction-Id:"
line["Transaction-Id:"] = ""
line = line.strip
transactionId = line
puts "!!!!!!!!!!!!!found " + transactionId + "!!!!!!!!!!!!!!!"
end
end
if transactionId.nil?
exit 1
end
return transactionId
end
old_rev, new_rev, ref_name = STDIN.gets.split
repo_name = File.basename(Dir.getwd)
puts "=============================="
puts "repo_name: " + repo_name + ""
puts "old_rev: " + old_rev + ""
puts "new_rev: " + new_rev + ""
puts "ref_name: " + ref_name + ""
puts "=============================="
repo = Grit::Repo.new(".")
# this is the head so we expect only one commit
commit = repo.commits(new_rev,1).last
puts "=============================="
puts commit.id + ""
puts commit.message + ""
transactionId = extractTransactionIdFromCommit commit
puts "=============================="
puts "=============================="
puts "Extracting parent ids"
parentTransactionIds = Array.new
if commit.parents != nil
commit.parents.each do |parent|
parentTransactionIds.push extractTransactionIdFromCommit parent
end
end
puts "=============================="
puts "=============================="
puts "Exec rest call"
puts "=============================="
restCall = 'http://localhost:4567/transaction?'
restCall += 'repository=' + repo_name
restCall += '&commit=' + new_rev
restCall += '&transaction=' + transactionId
restCall += '&parents='
parentTransactionIds.each do |parentTransactionId|
restCall += parentTransactionId + ","
end
response = RestClient.get restCall
puts "=============================="
puts "Finished rest call"
puts "=============================="
#exit 1