Skip to content

Commit 14de31d

Browse files
committed
Allow omitting token if api_base_url is file://
1 parent 0a60476 commit 14de31d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_send_app_size_metrics.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ module Fastlane
55
module Actions
66
class IosSendAppSizeMetricsAction < Action
77
def self.run(params)
8+
# Check input parameters
9+
base_url = URI(params[:api_base_url])
10+
api_token = params[:api_token]
11+
if (api_token.nil? || api_token.empty?) && !base_url.is_a?(URI::File)
12+
UI.user_error!('An API token is required when using an `api_base_url` with a scheme other than `file://`')
13+
end
14+
15+
# Build the payload base
816
payload = Fastlane::WPMRT::AppSizeMetricsPayload.new(
917
'App Name': params[:app_name],
1018
'Build Type': params[:build_type],
1119
'App Version': params[:app_version]
1220
)
1321
payload.add_metric(name: 'File Size', value: File.size(params[:ipa_path]))
1422

23+
# Add app-thinning metrics to the payload if a `.plist` is provided
1524
app_thinning_plist_path = params[:app_thinning_plist_path] || File.join(File.dirname(params[:ipa_path]), 'app-thinning.plist')
1625
if File.exist?(app_thinning_plist_path)
1726
plist = Plist.parse_xml(app_thinning_plist_path)
@@ -25,9 +34,10 @@ def self.run(params)
2534
end
2635
end
2736

37+
# Send the payload
2838
payload.send_metrics(
29-
base_url: params[:api_base_url],
30-
api_token: params[:api_token]
39+
base_url: base_url,
40+
api_token: api_token
3141
)
3242
end
3343

@@ -57,7 +67,7 @@ def self.available_options
5767
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_API_TOKEN',
5868
description: 'The bearer token to call to API',
5969
type: String,
60-
optional: false
70+
optional: true # Required unless `api_base_url` is a `file://` URL
6171
),
6272
FastlaneCore::ConfigItem.new(
6373
key: :app_name,

lib/fastlane/plugin/wpmreleasetoolkit/models/app_size_metrics_payload.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def to_h
4343
#
4444
# Must conform to the API described in https://github.com/Automattic/apps-metrics/wiki/Queue-Group-of-Metrics
4545
#
46-
# @param [String] base_url The base URL of the App Metrics service
46+
# @param [String,URI] base_url The base URL of the App Metrics service
4747
# @param [String] api_token The API bearer token to use to register the metric.
4848
# @return [Integer] the HTTP response code
4949
#
5050
def send_metrics(base_url:, api_token:)
51-
uri = URI.parse(base_url)
51+
uri = URI(base_url)
5252
# Allow using a `file:` URI for debugging
5353
if uri.is_a?(URI::File)
5454
UI.message("Writing metrics payload to file #{uri.path} (instead of sending it to a server)")

0 commit comments

Comments
 (0)