Skip to content

Commit e8430a9

Browse files
authored
Merge pull request #4 from Instabug/fix-issues-while-testing
Fix issues while testing + extract error message
2 parents 5048fe7 + dd1f09a commit e8430a9

File tree

6 files changed

+81
-18
lines changed

6 files changed

+81
-18
lines changed

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ def self.run(params)
88
UI.message("Starting Instabug Android build...")
99

1010
# Extract Instabug-specific parameters
11-
branch_name = params.delete(:branch_name)
12-
instabug_api_key = params.delete(:instabug_api_key)
11+
branch_name = params[:branch_name]
12+
instabug_api_key = params[:instabug_api_key]
1313

1414
# Validate required parameters
1515
if branch_name.nil? || branch_name.empty?
1616
UI.user_error!("branch_name is required for Instabug reporting")
1717
end
1818

19+
# Filter out Instabug-specific parameters before passing to gradle
20+
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::GradleAction)
21+
1922
begin
2023
# Report build start to Instabug
2124
Helper::InstabugStoresUploadHelper.report_status(
@@ -29,7 +32,7 @@ def self.run(params)
2932
build_start_time = Time.now
3033

3134
# Execute the actual Android build using gradle
32-
result = Actions::GradleAction.run(params)
35+
result = Actions::GradleAction.run(filtered_params)
3336

3437
# Calculate build time in seconds
3538
build_time = (Time.now - build_start_time).round
@@ -58,15 +61,16 @@ def self.run(params)
5861
UI.success("Android build completed successfully!")
5962
result
6063
rescue StandardError => e
61-
UI.error("Android build failed: #{e.message}")
64+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
65+
UI.error("Android build failed: #{error_message}")
6266

6367
# Report build failure to Instabug
6468
Helper::InstabugStoresUploadHelper.report_status(
6569
branch_name:,
6670
api_key: instabug_api_key,
6771
status: "failure",
6872
step: "build_app",
69-
error_message: e.message
73+
error_message: error_message
7074
)
7175
raise e
7276
end

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ def self.run(params)
88
UI.message("Starting Instabug iOS build...")
99

1010
# Extract Instabug-specific parameters
11-
branch_name = params.delete(:branch_name)
12-
instabug_api_key = params.delete(:instabug_api_key)
11+
branch_name = params[:branch_name]
12+
instabug_api_key = params[:instabug_api_key]
1313

1414
# Validate required parameters
1515
if branch_name.nil? || branch_name.empty?
1616
UI.user_error!("branch_name is required for Instabug reporting")
1717
end
1818

19+
# Filter out Instabug-specific parameters before passing to build_ios_app
20+
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::BuildIosAppAction)
21+
1922
begin
2023
# Report build start to Instabug
2124
Helper::InstabugStoresUploadHelper.report_status(
@@ -29,7 +32,7 @@ def self.run(params)
2932
build_start_time = Time.now
3033

3134
# Execute the actual iOS build
32-
result = Actions::BuildIosAppAction.run(params)
35+
result = Actions::BuildIosAppAction.run(filtered_params)
3336

3437
# Calculate build time in seconds
3538
build_time = (Time.now - build_start_time).round
@@ -58,15 +61,16 @@ def self.run(params)
5861
UI.success("iOS build completed successfully!")
5962
result
6063
rescue StandardError => e
61-
UI.error("iOS build failed: #{e.message}")
64+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
65+
UI.error("iOS build failed: #{error_message}")
6266

6367
# Report build failure to Instabug
6468
Helper::InstabugStoresUploadHelper.report_status(
6569
branch_name:,
6670
api_key: instabug_api_key,
6771
status: "failure",
6872
step: "build_app",
69-
error_message: e.message
73+
error_message: error_message
7074
)
7175
raise e
7276
end

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ def self.run(params)
88
UI.message("Starting Instabug App Store upload...")
99

1010
# Extract Instabug-specific parameters
11-
branch_name = params.delete(:branch_name)
12-
instabug_api_key = params.delete(:instabug_api_key)
11+
branch_name = params[:branch_name]
12+
instabug_api_key = params[:instabug_api_key]
1313

1414
# Validate required parameters
1515
if branch_name.nil? || branch_name.empty?
1616
UI.user_error!("branch_name is required for Instabug reporting")
1717
end
1818

19+
# Filter out Instabug-specific parameters before passing to upload_to_app_store
20+
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::UploadToAppStoreAction)
21+
1922
begin
2023
# Report upload start to Instabug
2124
Helper::InstabugStoresUploadHelper.report_status(
@@ -26,7 +29,7 @@ def self.run(params)
2629
)
2730

2831
# Execute the actual upload to App Store
29-
result = Actions::UploadToAppStoreAction.run(params)
32+
result = Actions::UploadToAppStoreAction.run(filtered_params)
3033

3134
# Report upload success to Instabug
3235
Helper::InstabugStoresUploadHelper.report_status(
@@ -39,7 +42,9 @@ def self.run(params)
3942
UI.success("App Store upload completed successfully!")
4043
result
4144
rescue StandardError => e
42-
UI.error("App Store upload failed: #{e.message}")
45+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
46+
47+
UI.error("App Store upload failed: #{error_message}")
4348

4449
# Report upload failure to Instabug
4550
Helper::InstabugStoresUploadHelper.report_status(

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ def self.run(params)
88
UI.message("Starting Instabug Play Store upload...")
99

1010
# Extract Instabug-specific parameters
11-
branch_name = params.delete(:branch_name)
12-
instabug_api_key = params.delete(:instabug_api_key)
11+
branch_name = params[:branch_name]
12+
instabug_api_key = params[:instabug_api_key]
1313

1414
# Validate required parameters
1515
if branch_name.nil? || branch_name.empty?
1616
UI.user_error!("branch_name is required for Instabug reporting")
1717
end
1818

19+
# Filter out Instabug-specific parameters before passing to upload_to_play_store
20+
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::UploadToPlayStoreAction)
21+
1922
begin
2023
# Report upload start to Instabug
2124
Helper::InstabugStoresUploadHelper.report_status(
@@ -26,7 +29,7 @@ def self.run(params)
2629
)
2730

2831
# Execute the actual upload to Play Store
29-
result = Actions::UploadToPlayStoreAction.run(params)
32+
result = Actions::UploadToPlayStoreAction.run(filtered_params)
3033

3134
# Report upload success to Instabug
3235
Helper::InstabugStoresUploadHelper.report_status(
@@ -39,7 +42,8 @@ def self.run(params)
3942
UI.success("Play Store upload completed successfully!")
4043
result
4144
rescue StandardError => e
42-
UI.error("Play Store upload failed: #{e.message}")
45+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
46+
UI.error("Play Store upload failed: #{error_message}")
4347

4448
# Report upload failure to Instabug
4549
Helper::InstabugStoresUploadHelper.report_status(

lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,49 @@ module Helper
1010
class InstabugStoresUploadHelper
1111
# Default Base URL for Instabug API
1212
DEFAULT_INSTABUG_API_BASE_URL = "https://api.instabug.com".freeze
13+
INSTABUG_KEYS = %i[branch_name instabug_api_key instabug_api_base_url].freeze
14+
15+
# Extract the important part of an error message
16+
def self.extract_error_message(error_message)
17+
return error_message unless error_message.is_a?(String)
18+
19+
lines = error_message.split("\n")
20+
start_index = lines.find_index { |line| line.strip.start_with?("* What went wrong:") }
21+
end_index = lines.find_index { |line| line.strip.start_with?("* Try:") }
22+
23+
if start_index && end_index && end_index > start_index
24+
extracted_lines = lines[(start_index + 1)...end_index].map(&:strip).reject(&:empty?)
25+
return extracted_lines.join(" ")[0, 250] unless extracted_lines.empty?
26+
end
27+
28+
# Fallback message
29+
"Your build was triggered but failed during execution. " \
30+
"This could be due to missing environment variables or incorrect build credentials. " \
31+
"Check CI logs for full details."
32+
end
1333

1434
def self.show_message
1535
UI.message("Hello from the instabug_stores_upload plugin helper!")
1636
end
1737

38+
# Filters out Instabug-specific parameters from the params configuration
39+
# and returns a new FastlaneCore::Configuration object with only the target action's parameters
40+
def self.filter_instabug_params(params, target_action_class)
41+
filtered_config = {}
42+
params.available_options.each do |option|
43+
key = option.key
44+
unless INSTABUG_KEYS.include?(key)
45+
value = params[key]
46+
filtered_config[key] = value if value
47+
end
48+
end
49+
50+
FastlaneCore::Configuration.create(
51+
target_action_class.available_options,
52+
filtered_config
53+
)
54+
end
55+
1856
def self.report_status(branch_name:, api_key:, status:, step:, extras: {}, error_message: nil)
1957
return unless branch_name.start_with?('crash-fix/instabug-crash-')
2058

spec/spec_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ module SpecHelper
1313
require 'fastlane/plugin/instabug_stores_upload' # import the actual plugin
1414
require 'webmock/rspec'
1515

16+
# Override the helper method for tests to handle plain hashes
17+
class Fastlane::Helper::InstabugStoresUploadHelper
18+
def self.filter_instabug_params(params, target_action_class)
19+
# In test environment, params are plain hashes - just filter them
20+
return params.reject { |key, _value| INSTABUG_KEYS.include?(key) }
21+
end
22+
end
23+
1624
Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values)
1725

1826
WebMock.disable_net_connect!(allow_localhost: true)

0 commit comments

Comments
 (0)