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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 30
def self.run(params) service_account_file_path = params[:service_account_file_path]
project_id = params[:project_id]
account_id = params[:account_id]
app_id = params[:app_id]
binary_path = params[:binary_path]
fail_on = params[:fail_on]
operation_id = params[:operation_id]
generate_report = params[:generate_report]
wait_for_report = params[:wait_for_report]
severity_threshold = params[:severity_threshold]
credentials = Fastlane::Checks::Credentials.new(key_file_path: service_account_file_path)
service = Fastlane::Checks::GoogleChecksService.new(credentials, project_id, account_id, app_id)
if generate_report
if operation_id.nil?
upload_spinner = TTY::Spinner.new("[:spinner] Uploading #{binary_path} to Google Checks...", format: :dots)
upload_spinner.auto_spin
begin
upload_response = service.upload_binary(binary_path)
rescue StandardError => e
UI.error(e)
UI.abort_with_message!("Error while uploading binary")
end
upload_spinner.success("Done")
end
if wait_for_report == false
UI.success("Skipping waiting for the report. Please visit https://checks.google.com to see the report.")
else
if operation_id.nil?
operation_id = Fastlane::Checks::GoogleChecksService.operation_id_from_name(upload_response["name"])
end
waiting_spinner = TTY::Spinner.new("[:spinner] Waiting for the report for operation id=#{operation_id}", format: :dots)
waiting_spinner.auto_spin
report_id, operation_response = service.wait_for_report(operation_id)
if report_id.nil?
waiting_spinner.error("Done")
UI.abort_with_message!("Failed to fetch the report")
else
waiting_spinner.success("Done")
report_response = service.report(report_id)
report_parser = Fastlane::Checks::ReportParser.new(severity_threshold)
failing_checks = report_parser.parse(report_response)
if failing_checks.empty? UI.success("No issues # rubocop:disable Metrics/BlockNestingdetected")
UI.success("Report console URL: #{operation_response['response']['resultsUri']}")
else
UI.error("#{failing_checks.length} issues detected:")
failing_checks.each do |check|
UI.error("Type: #{check['type']}. Details: #{check}")
end
if fail_on == 'all' UI.test_failure!("Report console URL: #{operation_response['response']['resultsUri']}")
else
UI.important("Report console URL: #{operation_response['response']['resultsUri']}")
end
end
end
end
else
response = service.apps_list
UI.message(response)
end
end
|