Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37721 - Hammer erratum list output is wrong when using content-view filter #945

Merged
merged 1 commit into from
Aug 13, 2024
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
15 changes: 13 additions & 2 deletions lib/hammer_cli_katello/erratum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@ class ListCommand < HammerCLIKatello::ListCommand
validate_options :before, 'IdResolution' do
organization_options = [:option_organization_id, :option_organization_name, \
:option_organization_label]
content_view_options = [:option_content_view_id, :option_content_view_name]

if option(:option_product_name).exist?
if option(:option_product_name).exist? || option(:option_content_view_name).exist?
any(*organization_options).required
end

if option(:option_content_view_version_version).exist?
any(*content_view_options).required
end

if any(*content_view_options).exist?
any(:option_content_view_version_id,
:option_content_view_version_version,
:option_environment_id,
:option_environment_name).required
end
end

build_options do |o|
o.expand.including(:products, :organizations, :content_views)
end

extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new)
end

Expand Down
15 changes: 15 additions & 0 deletions lib/hammer_cli_katello/id_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def repository_ids(options)
end

# rubocop:disable Style/EmptyElse
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def content_view_version_id(options)
key_id = HammerCLI.option_accessor_name("id")
key_content_view_id = HammerCLI.option_accessor_name("content_view_id")
Expand All @@ -128,7 +131,16 @@ def content_view_version_id(options)

options[key_content_view_id] ||= search_and_rescue(:content_view_id, "content_view", options)

if options[key_content_view_id] && options['option_environment_name'] &&
options['option_environment_id'].nil?
lifecycle_environment_resource_name = (HammerCLIForeman.param_to_resource('environment') ||
HammerCLIForeman.param_to_resource('lifecycle_environment')).singular_name
options['option_environment_id'] = lifecycle_environment_id(
scoped_options(lifecycle_environment_resource_name, options, :single))
end

results = find_resources(:content_view_versions, options)

options[from_environment_id] ||= from_lifecycle_environment_id(options)

return pick_result(results, @api.resource(:content_view_versions))['id'] if results.size == 1
Expand All @@ -145,6 +157,9 @@ def content_view_version_id(options)
end
end
# rubocop:enable Style/EmptyElse
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

private

Expand Down