Skip to content

Commit 9322fff

Browse files
authored
feat(get_prs_between_tags): add opt-in fail_on_error (#772)
2 parents 9e559f4 + 0b90010 commit 9322fff

3 files changed

Lines changed: 60 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _None_
1010

1111
### New Features
1212

13-
_None_
13+
- `get_prs_between_tags` now accepts a `fail_on_error:` parameter. [#772]
1414

1515
### Bug Fixes
1616

‎lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def self.run(params)
2525
config_file_path: config_file_path
2626
)
2727
rescue StandardError => e
28+
raise if params[:fail_on_error]
29+
2830
error_msg = "❌ Error computing the list of PRs since #{previous_tag || 'last release'}: `#{e.message}`"
2931
UI.important(error_msg)
3032
error_msg # Use error message as GitHub Release body to help us be aware of what went wrong.
@@ -102,6 +104,15 @@ def self.available_options
102104
'See https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options',
103105
optional: true,
104106
type: String),
107+
FastlaneCore::ConfigItem.new(key: :fail_on_error,
108+
description: 'Whether to fail the lane if the changelog cannot be computed. ' \
109+
'When `false` (the default), the error message is returned as the changelog itself, ' \
110+
'so that it ends up visible in the GitHub Release body. ' \
111+
'Set this to `true` if the caller publishes the release only after this action succeeds, ' \
112+
'and would rather stop than publish a release whose notes are an error message',
113+
optional: true,
114+
default_value: false,
115+
type: Boolean),
105116
Fastlane::Helper::GithubHelper.github_token_config_item,
106117
]
107118
end

‎spec/get_prs_between_tags_spec.rb‎

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
107107
end
108108

109109
describe 'error handling' do
110-
def test_with_params(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
111-
# Arrange
110+
def stub_failing_api_call(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
112111
allow(client).to receive(:post).with(
113112
"repos/#{test_repo}/releases/generate-notes",
114113
config_file_path: configuration_file_path,
115114
previous_tag_name: previous_tag,
116115
tag_name: test_tag_name,
117116
target_commitish: target_commitish || test_head_ref
118117
).and_raise(StandardError, error_msg)
118+
end
119+
120+
def test_with_params(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
121+
# Arrange
122+
stub_failing_api_call(
123+
target_commitish: target_commitish,
124+
previous_tag: previous_tag,
125+
configuration_file_path: configuration_file_path,
126+
error_msg: error_msg
127+
)
119128

120129
# Act
121130
result = run_described_fastlane_action(
@@ -154,5 +163,42 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
154163
error_msg: '400 - Invalid previous_tag parameter'
155164
)
156165
end
166+
167+
context 'when `fail_on_error` is enabled' do
168+
it 'raises instead of returning the error message as the changelog' do
169+
# Arrange
170+
stub_failing_api_call(previous_tag: '12.2', error_msg: 'API Failure')
171+
172+
# Act & Assert
173+
expect do
174+
run_described_fastlane_action(
175+
github_token: test_token,
176+
repository: test_repo,
177+
tag_name: test_tag_name,
178+
previous_tag: '12.2',
179+
fail_on_error: true
180+
)
181+
end.to raise_error(StandardError, 'API Failure')
182+
end
183+
end
184+
185+
context 'when `fail_on_error` is explicitly disabled' do
186+
it 'returns the error message as the changelog, like the default does' do
187+
# Arrange
188+
stub_failing_api_call(previous_tag: '12.2', error_msg: 'API Failure')
189+
190+
# Act
191+
result = run_described_fastlane_action(
192+
github_token: test_token,
193+
repository: test_repo,
194+
tag_name: test_tag_name,
195+
previous_tag: '12.2',
196+
fail_on_error: false
197+
)
198+
199+
# Assert
200+
expect(result).to eq('❌ Error computing the list of PRs since 12.2: `API Failure`')
201+
end
202+
end
157203
end
158204
end

0 commit comments

Comments
 (0)