Skip to content

Commit 5048fe7

Browse files
committed
applying review comment
1 parent 276b9e3 commit 5048fe7

File tree

4 files changed

+71
-114
lines changed

4 files changed

+71
-114
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def self.run(params)
3535
build_time = (Time.now - build_start_time).round
3636

3737
# Extract Android build path (APK or AAB)
38-
build_path = Helper::InstabugStoresUploadHelper.fetch_android_build_path(Actions.lane_context)
38+
build_path = fetch_android_build_path(Actions.lane_context)
3939

4040
if build_path.nil? || build_path.empty?
4141
UI.user_error!("Could not find any generated APK or AAB. Please check your gradle settings.")
@@ -147,6 +147,24 @@ def self.example_code
147147
def self.category
148148
:building
149149
end
150+
151+
# This helper method provides a clean and prioritized way to get the Android build output.
152+
# It checks for the most common output types in a specific order.
153+
# This is used to get the build path for the Android build artifact.
154+
def self.fetch_android_build_path(lane_context)
155+
build_keys = [
156+
SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS,
157+
SharedValues::GRADLE_APK_OUTPUT_PATH,
158+
SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS,
159+
SharedValues::GRADLE_AAB_OUTPUT_PATH
160+
]
161+
build_keys.each do |build_key|
162+
build_path = lane_context[build_key]
163+
return build_path if build_path && !build_path.empty?
164+
end
165+
166+
nil
167+
end
150168
end
151169
end
152170
end

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,6 @@ def self.report_status(branch_name:, api_key:, status:, step:, extras: {}, error
3030
)
3131
end
3232

33-
# This helper method provides a clean and prioritized way to get the Android build output.
34-
# It checks for the most common output types in a specific order.
35-
# This is used to get the build path for the Android build artifact.
36-
def self.fetch_android_build_path(lane_context)
37-
all_aab_paths = lane_context[Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS]
38-
return all_aab_paths if all_aab_paths && !all_aab_paths.empty?
39-
40-
aab_path = lane_context[Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH]
41-
return aab_path if aab_path && !aab_path.empty?
42-
43-
all_apk_paths = lane_context[Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
44-
return all_apk_paths if all_apk_paths && !all_apk_paths.empty?
45-
46-
apk_path = lane_context[Actions::SharedValues::GRADLE_APK_OUTPUT_PATH]
47-
return apk_path if apk_path && !apk_path.empty?
48-
49-
return nil
50-
end
51-
5233
def self.make_api_request(branch_name:, status:, api_key:, step:, extras: {}, error_message: nil)
5334
return unless api_key
5435

spec/instabug_build_android_app_action_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,58 @@
139139
end
140140
end
141141

142+
describe '.fetch_android_build_path' do
143+
let(:lane_context) { {} }
144+
145+
context 'when all AAB output paths are available' do
146+
it 'returns all AAB paths' do
147+
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] = ['/path/to/app1.aab', '/path/to/app2.aab']
148+
149+
result = described_class.fetch_android_build_path(lane_context)
150+
151+
expect(result).to eq(['/path/to/app1.aab', '/path/to/app2.aab'])
152+
end
153+
end
154+
155+
context 'when single AAB output path is available' do
156+
it 'returns single AAB path' do
157+
lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = '/path/to/app.aab'
158+
159+
result = described_class.fetch_android_build_path(lane_context)
160+
161+
expect(result).to eq('/path/to/app.aab')
162+
end
163+
end
164+
165+
context 'when all APK output paths are available' do
166+
it 'returns all APK paths' do
167+
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = ['/path/to/app1.apk', '/path/to/app2.apk']
168+
169+
result = described_class.fetch_android_build_path(lane_context)
170+
171+
expect(result).to eq(['/path/to/app1.apk', '/path/to/app2.apk'])
172+
end
173+
end
174+
175+
context 'when single APK output path is available' do
176+
it 'returns single APK path' do
177+
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = '/path/to/app.apk'
178+
179+
result = described_class.fetch_android_build_path(lane_context)
180+
181+
expect(result).to eq('/path/to/app.apk')
182+
end
183+
end
184+
185+
context 'when no build paths are available' do
186+
it 'returns nil' do
187+
result = described_class.fetch_android_build_path(lane_context)
188+
189+
expect(result).to be_nil
190+
end
191+
end
192+
end
193+
142194
describe 'metadata' do
143195
it 'has correct description' do
144196
expect(described_class.description).to eq('Build Android app with Instabug metadata reporting')

spec/instabug_stores_upload_helper_spec.rb

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,6 @@
22
require 'webmock/rspec'
33

44
describe Fastlane::Helper::InstabugStoresUploadHelper do
5-
describe '.fetch_android_build_path' do
6-
let(:lane_context) { {} }
7-
8-
context 'when all AAB output paths are available' do
9-
it 'returns all AAB paths with highest priority' do
10-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] = ['/path/to/app1.aab', '/path/to/app2.aab']
11-
lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = '/path/to/single.aab'
12-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = ['/path/to/app.apk']
13-
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = '/path/to/single.apk'
14-
15-
result = described_class.fetch_android_build_path(lane_context)
16-
17-
expect(result).to eq(['/path/to/app1.aab', '/path/to/app2.aab'])
18-
end
19-
end
20-
21-
context 'when single AAB output path is available' do
22-
it 'returns single AAB path when all AAB paths are not available' do
23-
lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = '/path/to/app.aab'
24-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = ['/path/to/app.apk']
25-
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = '/path/to/single.apk'
26-
27-
result = described_class.fetch_android_build_path(lane_context)
28-
29-
expect(result).to eq('/path/to/app.aab')
30-
end
31-
end
32-
33-
context 'when all APK output paths are available' do
34-
it 'returns all APK paths when AAB paths are not available' do
35-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = ['/path/to/app1.apk', '/path/to/app2.apk']
36-
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = '/path/to/single.apk'
37-
38-
result = described_class.fetch_android_build_path(lane_context)
39-
40-
expect(result).to eq(['/path/to/app1.apk', '/path/to/app2.apk'])
41-
end
42-
end
43-
44-
context 'when single APK output path is available' do
45-
it 'returns single APK path when other paths are not available' do
46-
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = '/path/to/app.apk'
47-
48-
result = described_class.fetch_android_build_path(lane_context)
49-
50-
expect(result).to eq('/path/to/app.apk')
51-
end
52-
end
53-
54-
context 'when no build paths are available' do
55-
it 'returns nil' do
56-
result = described_class.fetch_android_build_path(lane_context)
57-
58-
expect(result).to be_nil
59-
end
60-
end
61-
62-
context 'when paths are empty strings' do
63-
it 'returns nil for empty AAB path' do
64-
lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = ''
65-
66-
result = described_class.fetch_android_build_path(lane_context)
67-
68-
expect(result).to be_nil
69-
end
70-
71-
it 'returns nil for empty APK path' do
72-
lane_context[Fastlane::Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] = ''
73-
74-
result = described_class.fetch_android_build_path(lane_context)
75-
76-
expect(result).to be_nil
77-
end
78-
end
79-
80-
context 'when paths are empty arrays' do
81-
it 'returns nil for empty all AAB paths' do
82-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] = []
83-
84-
result = described_class.fetch_android_build_path(lane_context)
85-
86-
expect(result).to be_nil
87-
end
88-
89-
it 'returns nil for empty all APK paths' do
90-
lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = []
91-
92-
result = described_class.fetch_android_build_path(lane_context)
93-
94-
expect(result).to be_nil
95-
end
96-
end
97-
end
98-
995
describe '.report_status' do
1006
let(:api_endpoint) { 'https://api.instabug.com/api/web/public/agent_fastlane/status' }
1017

0 commit comments

Comments
 (0)