Skip to content

Fix issues while testing + extract error message #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -58,15 +61,16 @@ 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(
branch_name:,
api_key: instabug_api_key,
status: "failure",
step: "build_app",
error_message: e.message
error_message: error_message
)
raise e
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -58,15 +61,16 @@ 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(
branch_name:,
api_key: instabug_api_key,
status: "failure",
step: "build_app",
error_message: e.message
error_message: error_message
)
raise e
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-')

Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)