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
|
# File 'fastlane/lib/fastlane/actions/github_api.rb', line 11
def run(params)
require 'json'
http_method = (params[:http_method] || 'GET').to_s.upcase
url = construct_url(params[:server_url], params[:path], params[:url])
= (params[:api_token], params[:headers])
payload = construct_body(params[:body], params[:raw_body])
error_handlers = params[:error_handlers] || {}
secure = params[:secure]
response = call_endpoint(
url,
http_method,
,
payload,
secure
)
status_code = response[:status]
result = {
status: status_code,
body: response.body || "",
json: parse_json(response.body) || {}
}
if status_code.between?(200, 299)
UI.verbose("Response:")
UI.verbose(response.body)
UI.verbose("---")
yield(result) if block_given?
else
handled_error = error_handlers[status_code] || error_handlers['*']
if handled_error
handled_error.call(result)
else
UI.error("---")
UI.error("Request failed:\n#{http_method}: #{url}")
UI.error("Headers:\n#{}")
UI.error("---")
UI.error("Response:")
UI.error(response.body)
UI.user_error!("GitHub responded with #{status_code}\n---\n#{response.body}")
end
end
Actions.lane_context[SharedValues::GITHUB_API_STATUS_CODE] = result[:status]
Actions.lane_context[SharedValues::GITHUB_API_RESPONSE] = result[:body]
Actions.lane_context[SharedValues::GITHUB_API_JSON] = result[:json]
return result
end
|