Class: Fastlane::Helper::EmergeHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::EmergeHelper
- Defined in:
- lib/fastlane/plugin/emerge/helper/emerge_helper.rb
Constant Summary collapse
- API_URL =
'https://api.emergetools.com/upload'.freeze
Class Method Summary collapse
- .clean_params(params) ⇒ Object
- .copy_config(config_path, tmp_dir) ⇒ Object
- .create_upload(api_token, params) ⇒ Object
- .handle_upload_response(api_token, response, file_path) ⇒ Object
- .headers(api_token, params, content_type) ⇒ Object
- .make_git_params ⇒ Object
- .parse_response(response) ⇒ Object
- .perform_upload(api_token, params, file_path) ⇒ Object
- .print_summary(params) ⇒ Object
- .upload_file(api_token, upload_url, file_path) ⇒ Object
Class Method Details
.clean_params(params) ⇒ Object
73 74 75 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 73 def self.clean_params(params) params.reject { |_, v| v.nil? } end |
.copy_config(config_path, tmp_dir) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 58 def self.copy_config(config_path, tmp_dir) return if config_path.nil? = File.(config_path) unless File.exist?() UI.error("No config file found at path '#{}'.\nUploading without config file") return end emerge_config_path = "#{tmp_dir}/emerge_config.yaml" FileUtils.cp(, emerge_config_path) end |
.create_upload(api_token, params) ⇒ Object
85 86 87 88 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 85 def self.create_upload(api_token, params) response = Faraday.post(API_URL, params.to_json, headers(api_token, params, 'application/json')) parse_response(response) end |
.handle_upload_response(api_token, response, file_path) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 112 def self.handle_upload_response(api_token, response, file_path) upload_url = response.fetch('uploadURL') upload_id = response.fetch('upload_id') warning = response.dig('warning') if warning UI.important(warning) end UI.('Starting zip file upload') upload_file(api_token, upload_url, file_path) upload_id end |
.headers(api_token, params, content_type) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 90 def self.headers(api_token, params, content_type) { 'Content-Type' => content_type, 'X-API-Token' => api_token, 'User-Agent' => "fastlane-plugin-emerge/#{Fastlane::Emerge::VERSION}" } end |
.make_git_params ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 34 def self.make_git_params git_result = if Helper::Github.is_supported_github_event? UI.("Fetching Git info from Github event") GitResult.new( sha: Helper::Github.sha, base_sha: Helper::Github.base_sha, previous_sha: Helper::Github.previous_sha, branch: Helper::Github.branch, pr_number: Helper::Github.pr_number, repo_name: Helper::Github.repo_name ) else UI.("Fetching Git info from system Git") GitResult.new( sha: Helper::Git.sha, base_sha: Helper::Git.base_sha, previous_sha: Helper::Git.previous_sha, branch: Helper::Git.branch ) end UI.("Got git result #{git_result.inspect}") git_result end |
.parse_response(response) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 98 def self.parse_response(response) case response.status when 200 JSON.parse(response.body) when 400 = JSON.parse(response.body)['errorMessage'] raise "Invalid parameters: #{}" when 401, 403 raise 'Invalid API token' else raise "Creating upload failed with status #{response.status}" end end |
.perform_upload(api_token, params, file_path) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 24 def self.perform_upload(api_token, params, file_path) cleaned_params = clean_params(params) print_summary(cleaned_params) upload_response = create_upload(api_token, cleaned_params) handle_upload_response(api_token, upload_response, file_path) rescue StandardError => e UI.user_error!(e.) end |
.print_summary(params) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 77 def self.print_summary(params) FastlaneCore::PrintTable.print_values( config: params, hide_keys: [], title: "Summary for Emerge Upload #{Fastlane::Emerge::VERSION}" ) end |
.upload_file(api_token, upload_url, file_path) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/fastlane/plugin/emerge/helper/emerge_helper.rb', line 126 def self.upload_file(api_token, upload_url, file_path) response = Faraday.put(upload_url) do |req| req.headers = headers(api_token, nil, 'application/zip') req.headers['Content-Length'] = File.size(file_path).to_s req.body = Faraday::UploadIO.new(file_path, 'application/zip') end raise "Uploading zip file failed #{response.status}" unless response.status == 200 end |