10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/captive_release/github_http.rb', line 10
def github_post(uri, token, body)
MAX_REDIRECTS.times do
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path)
request["Authorization"] = "token #{token}"
request["Content-Type"] = "application/json"
request["Accept"] = "application/vnd.github+json"
request["X-GitHub-Api-Version"] = "2022-11-28"
request.body = body
response = http.request(request)
return response unless %w[301 302 307 308].include?(response.code)
location = response["location"] || response["Location"]
raise "GitHub redirect without Location header" unless location
uri = URI(location)
end
raise "Too many redirects from GitHub API"
end
|