diff --git a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb index 81181c8..1e1682d 100644 --- a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb +++ b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb @@ -8,14 +8,17 @@ def self.run(params) UI.message("Starting Instabug Android build...") # Extract Instabug-specific parameters - branch_name = params.delete(:branch_name) - instabug_api_key = params.delete(:instabug_api_key) + branch_name = params[:branch_name] + instabug_api_key = params[:instabug_api_key] # Validate required parameters if branch_name.nil? || branch_name.empty? UI.user_error!("branch_name is required for Instabug reporting") end + # Filter out Instabug-specific parameters before passing to gradle + filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::GradleAction) + begin # Report build start to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -29,7 +32,7 @@ def self.run(params) build_start_time = Time.now # Execute the actual Android build using gradle - result = Actions::GradleAction.run(params) + result = Actions::GradleAction.run(filtered_params) # Calculate build time in seconds build_time = (Time.now - build_start_time).round @@ -58,7 +61,8 @@ def self.run(params) UI.success("Android build completed successfully!") result rescue StandardError => e - UI.error("Android build failed: #{e.message}") + error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message) + UI.error("Android build failed: #{error_message}") # Report build failure to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -66,7 +70,7 @@ def self.run(params) api_key: instabug_api_key, status: "failure", step: "build_app", - error_message: e.message + error_message: error_message ) raise e end diff --git a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb index 114f7bd..1c23b92 100644 --- a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb +++ b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb @@ -8,14 +8,17 @@ def self.run(params) UI.message("Starting Instabug iOS build...") # Extract Instabug-specific parameters - branch_name = params.delete(:branch_name) - instabug_api_key = params.delete(:instabug_api_key) + branch_name = params[:branch_name] + instabug_api_key = params[:instabug_api_key] # Validate required parameters if branch_name.nil? || branch_name.empty? UI.user_error!("branch_name is required for Instabug reporting") end + # Filter out Instabug-specific parameters before passing to build_ios_app + filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::BuildIosAppAction) + begin # Report build start to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -29,7 +32,7 @@ def self.run(params) build_start_time = Time.now # Execute the actual iOS build - result = Actions::BuildIosAppAction.run(params) + result = Actions::BuildIosAppAction.run(filtered_params) # Calculate build time in seconds build_time = (Time.now - build_start_time).round @@ -58,7 +61,8 @@ def self.run(params) UI.success("iOS build completed successfully!") result rescue StandardError => e - UI.error("iOS build failed: #{e.message}") + error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message) + UI.error("iOS build failed: #{error_message}") # Report build failure to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -66,7 +70,7 @@ def self.run(params) api_key: instabug_api_key, status: "failure", step: "build_app", - error_message: e.message + error_message: error_message ) raise e end diff --git a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb index 2a02b10..ef14569 100644 --- a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb +++ b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb @@ -8,14 +8,17 @@ def self.run(params) UI.message("Starting Instabug App Store upload...") # Extract Instabug-specific parameters - branch_name = params.delete(:branch_name) - instabug_api_key = params.delete(:instabug_api_key) + branch_name = params[:branch_name] + instabug_api_key = params[:instabug_api_key] # Validate required parameters if branch_name.nil? || branch_name.empty? UI.user_error!("branch_name is required for Instabug reporting") end + # Filter out Instabug-specific parameters before passing to upload_to_app_store + filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::UploadToAppStoreAction) + begin # Report upload start to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -26,7 +29,7 @@ def self.run(params) ) # Execute the actual upload to App Store - result = Actions::UploadToAppStoreAction.run(params) + result = Actions::UploadToAppStoreAction.run(filtered_params) # Report upload success to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -39,7 +42,9 @@ def self.run(params) UI.success("App Store upload completed successfully!") result rescue StandardError => e - UI.error("App Store upload failed: #{e.message}") + error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message) + + UI.error("App Store upload failed: #{error_message}") # Report upload failure to Instabug Helper::InstabugStoresUploadHelper.report_status( diff --git a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb index 5f91fc0..b183c3d 100644 --- a/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb +++ b/lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb @@ -8,14 +8,17 @@ def self.run(params) UI.message("Starting Instabug Play Store upload...") # Extract Instabug-specific parameters - branch_name = params.delete(:branch_name) - instabug_api_key = params.delete(:instabug_api_key) + branch_name = params[:branch_name] + instabug_api_key = params[:instabug_api_key] # Validate required parameters if branch_name.nil? || branch_name.empty? UI.user_error!("branch_name is required for Instabug reporting") end + # Filter out Instabug-specific parameters before passing to upload_to_play_store + filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::UploadToPlayStoreAction) + begin # Report upload start to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -26,7 +29,7 @@ def self.run(params) ) # Execute the actual upload to Play Store - result = Actions::UploadToPlayStoreAction.run(params) + result = Actions::UploadToPlayStoreAction.run(filtered_params) # Report upload success to Instabug Helper::InstabugStoresUploadHelper.report_status( @@ -39,7 +42,8 @@ def self.run(params) UI.success("Play Store upload completed successfully!") result rescue StandardError => e - UI.error("Play Store upload failed: #{e.message}") + error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message) + UI.error("Play Store upload failed: #{error_message}") # Report upload failure to Instabug Helper::InstabugStoresUploadHelper.report_status( diff --git a/lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb b/lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb index 6165c3c..8a1407a 100644 --- a/lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb +++ b/lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb @@ -10,11 +10,49 @@ module Helper class InstabugStoresUploadHelper # Default Base URL for Instabug API DEFAULT_INSTABUG_API_BASE_URL = "https://api.instabug.com".freeze + INSTABUG_KEYS = %i[branch_name instabug_api_key instabug_api_base_url].freeze + + # Extract the important part of an error message + def self.extract_error_message(error_message) + return error_message unless error_message.is_a?(String) + + lines = error_message.split("\n") + start_index = lines.find_index { |line| line.strip.start_with?("* What went wrong:") } + end_index = lines.find_index { |line| line.strip.start_with?("* Try:") } + + if start_index && end_index && end_index > start_index + extracted_lines = lines[(start_index + 1)...end_index].map(&:strip).reject(&:empty?) + return extracted_lines.join(" ")[0, 250] unless extracted_lines.empty? + end + + # Fallback message + "Your build was triggered but failed during execution. " \ + "This could be due to missing environment variables or incorrect build credentials. " \ + "Check CI logs for full details." + end def self.show_message UI.message("Hello from the instabug_stores_upload plugin helper!") end + # Filters out Instabug-specific parameters from the params configuration + # and returns a new FastlaneCore::Configuration object with only the target action's parameters + def self.filter_instabug_params(params, target_action_class) + filtered_config = {} + params.available_options.each do |option| + key = option.key + unless INSTABUG_KEYS.include?(key) + value = params[key] + filtered_config[key] = value if value + end + end + + FastlaneCore::Configuration.create( + target_action_class.available_options, + filtered_config + ) + end + def self.report_status(branch_name:, api_key:, status:, step:, extras: {}, error_message: nil) return unless branch_name.start_with?('crash-fix/instabug-crash-') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5e2f9a6..d3f0aef 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,14 @@ module SpecHelper require 'fastlane/plugin/instabug_stores_upload' # import the actual plugin require 'webmock/rspec' +# Override the helper method for tests to handle plain hashes +class Fastlane::Helper::InstabugStoresUploadHelper + def self.filter_instabug_params(params, target_action_class) + # In test environment, params are plain hashes - just filter them + return params.reject { |key, _value| INSTABUG_KEYS.include?(key) } + end +end + Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values) WebMock.disable_net_connect!(allow_localhost: true)