-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep.rb
More file actions
86 lines (68 loc) · 1.93 KB
/
step.rb
File metadata and controls
86 lines (68 loc) · 1.93 KB
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
76
77
78
79
80
81
82
83
84
85
require 'net/http'
require 'net/https'
require 'json/ext'
def sendPutRequest(url, body=nil)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_version = :TLSv1
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
req = Net::HTTP::Put.new(uri.path)
req['Authorization'] = "token #{@authorization_token}"
req.body = body unless body.nil?
http.request(req)
end
def sendGetRequest(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_version = :TLSv1
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
req = Net::HTTP::Get.new(uri.path)
req['Authorization'] = "token #{@authorization_token}"
http.request(req)
end
url = ENV["repository_url"]
if url.to_s.eql? ''
puts "No repository url specified :>#{url}<"
exit 1
end
unless (/([A-Za-z0-9]+@|http(|s)\:\/\/)(github.com)(:|\/)(?<user>[A-Za-z0-9]+)\/(?<repo>[^.]+)(\.git)?/ =~ url) == 0
puts "#{url} is not a GitHub repository"
exit 1
end
build_is_green = ENV["STEPLIB_BUILD_STATUS"] == "0"
commit_hash = ENV["commit_hash"]
@authorization_token = ENV["auth_token"]
pull_id = ENV["pull_id"]
if commit_hash.to_s.eql? ''
puts "No commit hash specified"
exit 1
end
if @authorization_token.to_s.eql? ''
puts "No authorization_token specified"
exit 1
end
if pull_id.to_s.eql? ''
puts "No build url specified"
exit 1
end
#lecture pull/number
url = "https://api.github.com/repos/#{user}/#{repo}/pulls/#{pull_id}"
response = sendGetRequest url
data = JSON.parse response.body
statuses_url=data["statuses_url"]
puts data["mergeable_state"]
#lecture statuses
#if state == success
# merge
#end
commit_hash = statuses_url.split('/').last
url= "https://api.github.com/repos/#{user}/#{repo}/pulls/#{pull_id}/merge"
body = {
commit_message:"merged by BBM",
sha: commit_hash
}.to_json
puts url +" " + body
response = sendPutRequest url, body
exit (response.code.eql?('200') ? 0 : 1)