Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _None_

### New Features

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

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def self.run(params)
config_file_path: config_file_path
)
rescue StandardError => e
raise if params[:fail_on_error]

error_msg = "❌ Error computing the list of PRs since #{previous_tag || 'last release'}: `#{e.message}`"
UI.important(error_msg)
error_msg # Use error message as GitHub Release body to help us be aware of what went wrong.
Expand Down Expand Up @@ -102,6 +104,15 @@ def self.available_options
'See https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options',
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :fail_on_error,
description: 'Whether to fail the lane if the changelog cannot be computed. ' \
'When `false` (the default), the error message is returned as the changelog itself, ' \
'so that it ends up visible in the GitHub Release body. ' \
'Set this to `true` if the caller publishes the release only after this action succeeds, ' \
'and would rather stop than publish a release whose notes are an error message',
optional: true,
default_value: false,
type: Boolean),
Fastlane::Helper::GithubHelper.github_token_config_item,
]
end
Expand Down
50 changes: 48 additions & 2 deletions spec/get_prs_between_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,24 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
end

describe 'error handling' do
def test_with_params(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
# Arrange
def stub_failing_api_call(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
allow(client).to receive(:post).with(
"repos/#{test_repo}/releases/generate-notes",
config_file_path: configuration_file_path,
previous_tag_name: previous_tag,
tag_name: test_tag_name,
target_commitish: target_commitish || test_head_ref
).and_raise(StandardError, error_msg)
end

def test_with_params(target_commitish: nil, previous_tag: nil, configuration_file_path: nil, error_msg: 'API Failure')
# Arrange
stub_failing_api_call(
target_commitish: target_commitish,
previous_tag: previous_tag,
configuration_file_path: configuration_file_path,
error_msg: error_msg
)

# Act
result = run_described_fastlane_action(
Expand Down Expand Up @@ -154,5 +163,42 @@ def test_with_params(target_commitish: nil, previous_tag: nil, configuration_fil
error_msg: '400 - Invalid previous_tag parameter'
)
end

context 'when `fail_on_error` is enabled' do
it 'raises instead of returning the error message as the changelog' do
# Arrange
stub_failing_api_call(previous_tag: '12.2', error_msg: 'API Failure')

# Act & Assert
expect do
run_described_fastlane_action(
github_token: test_token,
repository: test_repo,
tag_name: test_tag_name,
previous_tag: '12.2',
fail_on_error: true
)
end.to raise_error(StandardError, 'API Failure')
end
end

context 'when `fail_on_error` is explicitly disabled' do
it 'returns the error message as the changelog, like the default does' do
# Arrange
stub_failing_api_call(previous_tag: '12.2', error_msg: 'API Failure')

# Act
result = run_described_fastlane_action(
github_token: test_token,
repository: test_repo,
tag_name: test_tag_name,
previous_tag: '12.2',
fail_on_error: false
)

# Assert
expect(result).to eq('❌ Error computing the list of PRs since 12.2: `API Failure`')
end
end
end
end