Skip to content

Commit 49e0c21

Browse files
committed
Rename api_base_url to api_url
Since we expect it to point to the full URL, including the `/api/grouped-metrics` path, in order to be as flexible as possible
1 parent f1fc01a commit 49e0c21

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_send_app_size_metrics.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module Actions
55
class AndroidSendAppSizeMetricsAction < Action
66
def self.run(params)
77
# Check input parameters
8-
base_url = URI(params[:api_base_url])
8+
api_url = URI(params[:api_url])
99
api_token = params[:api_token]
10-
if (api_token.nil? || api_token.empty?) && !base_url.is_a?(URI::File)
11-
UI.user_error!('An API token is required when using an `api_base_url` with a scheme other than `file://`')
10+
if (api_token.nil? || api_token.empty?) && !api_url.is_a?(URI::File)
11+
UI.user_error!('An API token is required when using an `api_url` with a scheme other than `file://`')
1212
end
1313

1414
# Build the payload base
@@ -48,7 +48,7 @@ def self.run(params)
4848

4949
# Send the payload
5050
metrics_helper.send_metrics(
51-
base_url: base_url,
51+
to: api_url,
5252
api_token: api_token,
5353
use_gzip: params[:use_gzip_content_encoding]
5454
)
@@ -82,24 +82,24 @@ def self.details
8282
8383
See https://github.com/Automattic/apps-metrics for the API contract expected by the Metrics server you will send those metrics to.
8484
85-
Tip: If you provide a `file://` URL for the `api_base_url`, the action will write the payload on disk at the specified path instead of sending
85+
Tip: If you provide a `file://` URL for the `api_url`, the action will write the payload on disk at the specified path instead of sending
8686
the data to a endpoint over network. This can be useful e.g. to inspect the payload and debug it, or to store the metrics data as CI artefacts.
8787
DETAILS
8888
end
8989

9090
def self.available_options
9191
[
9292
FastlaneCore::ConfigItem.new(
93-
key: :api_base_url,
94-
env_name: 'FL_ANDROID_SEND_APP_SIZE_METRICS_API_BASE_URL',
93+
key: :api_url,
94+
env_name: 'FL_ANDROID_SEND_APP_SIZE_METRICS_API_URL',
9595
description: 'The endpoint API URL to publish metrics to. (Note: you can also point to a `file://` URL to write the payload to a file instead)',
9696
type: String,
9797
optional: false
9898
),
9999
FastlaneCore::ConfigItem.new(
100100
key: :api_token,
101101
env_name: 'FL_ANDROID_SEND_APP_SIZE_METRICS_API_TOKEN',
102-
description: 'The bearer token to call the API. Required, unless `api_base_url` is a `file://` URL',
102+
description: 'The bearer token to call the API. Required, unless `api_url` is a `file://` URL',
103103
type: String,
104104
optional: true
105105
),

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Actions
66
class IosSendAppSizeMetricsAction < Action
77
def self.run(params)
88
# Check input parameters
9-
base_url = URI(params[:api_base_url])
9+
api_url = URI(params[:api_url])
1010
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://`')
11+
if (api_token.nil? || api_token.empty?) && !api_url.is_a?(URI::File)
12+
UI.user_error!('An API token is required when using an `api_url` with a scheme other than `file://`')
1313
end
1414

1515
# Build the payload base
@@ -38,7 +38,7 @@ def self.run(params)
3838

3939
# Send the payload
4040
metrics_helper.send_metrics(
41-
base_url: base_url,
41+
to: api_url,
4242
api_token: api_token,
4343
use_gzip: params[:use_gzip_content_encoding]
4444
)
@@ -66,24 +66,24 @@ def self.details
6666
6767
See https://github.com/Automattic/apps-metrics for the API contract expected by the Metrics server you are expected to send those metrics to.
6868
69-
Tip: If you provide a `file://` URL for the `api_base_url`, the action will write the payload on disk at the specified path instead of sending
69+
Tip: If you provide a `file://` URL for the `api_url`, the action will write the payload on disk at the specified path instead of sending
7070
the data to a endpoint over network. This can be useful e.g. to inspect the payload and debug it, or to store the metrics data as CI artefacts.
7171
DETAILS
7272
end
7373

7474
def self.available_options
7575
[
7676
FastlaneCore::ConfigItem.new(
77-
key: :api_base_url,
78-
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_API_BASE_URL',
77+
key: :api_url,
78+
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_API_URL',
7979
description: 'The endpoint API URL to publish metrics to. (Note: you can also point to a `file://` URL to write the payload to a file instead)',
8080
type: String,
8181
optional: false
8282
),
8383
FastlaneCore::ConfigItem.new(
8484
key: :api_token,
8585
env_name: 'FL_IOS_SEND_APP_SIZE_METRICS_API_TOKEN',
86-
description: 'The bearer token to call the API. Required, unless `api_base_url` is a `file://` URL',
86+
description: 'The bearer token to call the API. Required, unless `api_url` is a `file://` URL',
8787
type: String,
8888
optional: true
8989
),

lib/fastlane/plugin/wpmreleasetoolkit/helper/app_size_metrics_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def to_h
4949
#
5050
# Must conform to the API described in https://github.com/Automattic/apps-metrics/wiki/Queue-Group-of-Metrics
5151
#
52-
# @param [String,URI] base_url The base URL of the App Metrics service
52+
# @param [String,URI] to The URL of the App Metrics service, or a `file://` URL to write the payload to disk
5353
# @param [String] api_token The API bearer token to use to register the metric.
5454
# @return [Integer] the HTTP response code
5555
#
56-
def send_metrics(base_url:, api_token:, use_gzip: true)
57-
uri = URI(base_url)
56+
def send_metrics(to:, api_token:, use_gzip: true)
57+
uri = URI(to)
5858
json_payload = use_gzip ? Zlib.gzip(to_h.to_json) : to_h.to_json
5959

6060
# Allow using a `file:` URI for debugging

spec/android_send_app_size_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_app_size_action(fake_aab_size:, fake_apks:, expected_payload:, **other_
3333

3434
# Act
3535
code = run_described_fastlane_action(
36-
api_base_url: File.join('file://localhost/', output_file),
36+
api_url: File.join('file://localhost/', output_file),
3737
aab_path: aab_path,
3838
**other_action_args
3939
)

spec/app_size_metrics_helper_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
it 'writes the payload uncompressed to a file when disabling gzip' do
8080
in_tmp_dir do |tmp_dir|
8181
output_file = File.join(tmp_dir, 'payload.json')
82-
base_url = File.join('file://localhost/', output_file)
82+
file_url = File.join('file://localhost/', output_file)
8383

84-
code = metrics_helper.send_metrics(base_url: base_url, api_token: nil, use_gzip: false)
84+
code = metrics_helper.send_metrics(to: file_url, api_token: nil, use_gzip: false)
8585

8686
expect(code).to eq(201)
8787
expect(File).to exist(output_file)
@@ -93,9 +93,9 @@
9393
it 'writes the payload compressed to a file when enabling gzip' do
9494
in_tmp_dir do |tmp_dir|
9595
output_file = File.join(tmp_dir, 'payload.json.gz')
96-
base_url = File.join('file://localhost/', output_file)
96+
file_url = File.join('file://localhost/', output_file)
9797

98-
code = metrics_helper.send_metrics(base_url: base_url, api_token: nil, use_gzip: true)
98+
code = metrics_helper.send_metrics(to: file_url, api_token: nil, use_gzip: true)
9999

100100
expect(code).to eq(201)
101101
expect(File).to exist(output_file)
@@ -106,7 +106,7 @@
106106
end
107107

108108
context 'when using non-file:// scheme for the URL' do
109-
let(:base_url) { 'https://fake-metrics-server/api/grouped-metrics' }
109+
let(:api_url) { 'https://fake-metrics-server/api/grouped-metrics' }
110110
let(:token) { 'fake#tokn' }
111111

112112
it 'sends the payload uncompressed to the server and with the right headers when disabling gzip' do
@@ -116,11 +116,11 @@
116116
'Content-Type': 'application/json'
117117
}
118118
last_received_body = nil
119-
stub = stub_request(:post, base_url).with(headers: expected_headers) do |req|
119+
stub = stub_request(:post, api_url).with(headers: expected_headers) do |req|
120120
last_received_body = req.body
121121
end.to_return(status: 201)
122122

123-
code = metrics_helper.send_metrics(base_url: base_url, api_token: token, use_gzip: false)
123+
code = metrics_helper.send_metrics(to: api_url, api_token: token, use_gzip: false)
124124

125125
expect(code).to eq(201)
126126
expect(stub).to have_been_made.once
@@ -135,11 +135,11 @@
135135
'Content-Encoding': 'gzip'
136136
}
137137
last_received_body = nil
138-
stub = stub_request(:post, base_url).with(headers: expected_headers) do |req|
138+
stub = stub_request(:post, api_url).with(headers: expected_headers) do |req|
139139
last_received_body = req.body
140140
end.to_return(status: 201)
141141

142-
code = metrics_helper.send_metrics(base_url: base_url, api_token: token, use_gzip: true)
142+
code = metrics_helper.send_metrics(to: api_url, api_token: token, use_gzip: true)
143143

144144
expect(code).to eq(201)
145145
expect(stub).to have_been_made.once

spec/ios_send_app_size_metrics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_app_size_action(fake_ipa_size:, expected_payload:, **other_action_args)
1414

1515
# Act
1616
code = run_described_fastlane_action(
17-
api_base_url: File.join('file://localhost/', output_file),
17+
api_url: File.join('file://localhost/', output_file),
1818
ipa_path: ipa_path,
1919
**other_action_args
2020
)

0 commit comments

Comments
 (0)