-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub.rb
64 lines (47 loc) · 1.36 KB
/
github.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
require 'net/http'
require 'json'
class Github
attr_reader :base_uri
attr_reader :base_headers
def initialize(token)
@base_uri = 'https://api.github.com/repos/rhardih/stand'
@base_headers = {
'Accept' => 'application/vnd.github+json',
'Authorization' => "Bearer #{token}",
'X-GitHub-Api-Version' => '2022-11-28'
}
end
def trigger_build(ndk:, platform:, toolchain:, tag:)
uri = URI("#{base_uri}/dispatches")
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri, base_headers)
if ndk.nil?
puts "TriggerBuild: ndk required"
exit
end
payload = {
event_type: "on-demand-build-image",
client_payload: {
ndk: ndk,
platform: platform,
toolchain: toolchain
}
}
req.body = payload.to_json
http.request(req)
end
def active_workflow_runs?
uri = URI("#{base_uri}/actions/runs")
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
p base_headers
req = Net::HTTP::Get.new(uri, base_headers)
response = http.request(req)
unless response.is_a?(Net::HTTPSuccess)
raise Net::HTTPError.new(response.code, response.message)
end
parsed = JSON.parse(response.body)
parsed["workflow_runs"].any? { |workflow| workflow["status"] == "in_progress" }
end
end