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

Onceover show Puppetfile - Add versionomy support for DSC module version format #328

Merged
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 lib/onceover/cli/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.command
summary 'Shows the current state of the puppetfile'
description <<-DESCRIPTION
Shows the state of the puppetfile including current versions and
laetst versions of each module. Great for checking for updates.
latest versions of each module. Great for checking for updates.
To update all modules run `onceover update puppetfile`. (Hint: once
you have done the update, run the tests to make sure nothing breaks.)
DESCRIPTION
Expand Down
88 changes: 58 additions & 30 deletions lib/onceover/controlrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,46 +232,74 @@ def print_puppetfile_table

output_array = []
threads = []
error_array = []
puppetfile.modules.each do |mod|
threads << Thread.new do
row = []
logger.debug "Loading data for #{mod.full_name}"
row << mod.full_name
if mod.is_a?(R10K::Module::Forge)
row << mod.expected_version
row << mod.v3_module.current_release.version

current = Versionomy.parse(mod.expected_version)
latest = Versionomy.parse(mod.v3_module.current_release.version)
row << if current.major < latest.major
"Major".red
elsif current.minor < latest.minor
"Minor".yellow
elsif current.tiny < latest.tiny
"Tiny".green
else
"No".green
end

row << mod.v3_module.endorsement
superseded_by = mod.v3_module.superseded_by
row << (superseded_by.nil? ? '' : superseded_by[:slug])
else
row << "N/A"
row << "N/A"
row << "N/A"
row << "N/A"
row << "N/A"
begin
row = []
logger.debug "Loading data for #{mod.full_name}"
row << mod.full_name
if mod.is_a?(R10K::Module::Forge)
row << mod.expected_version
row << mod.v3_module.current_release.version

# Configure a custom version format to support modern Puppet Forge versions.
# (major.minor.tiny-patchlevel-patchlevel_minor)
# e.g. 8.5.0-0-2
puppetforge_format = Versionomy.default_format.modified_copy do
field(:patchlevel_minor) do
recognize_number(:default_value_optional => true,
:delimiter_regexp => '-',
:default_delimiter => '-')
end
end

current = puppetforge_format.parse(mod.expected_version)
latest = puppetforge_format.parse(mod.v3_module.current_release.version)
row << if current.major < latest.major
"Major".red
elsif current.minor < latest.minor
"Minor".yellow
elsif current.tiny < latest.tiny
"Tiny".green
elsif current.patchlevel < latest.patchlevel
"PatchLevel".green
elsif current.patchlevel_minor < latest.patchlevel_minor
"PatchLevel_minor".green
else
"No".green
end

row << mod.v3_module.endorsement
superseded_by = mod.v3_module.superseded_by
row << (superseded_by.nil? ? '' : superseded_by[:slug])
else
row << "N/A"
row << "N/A"
row << "N/A"
row << "N/A"
row << "N/A"
end
output_array << row
rescue RuntimeError => e
error = []
error << mod.full_name
error << mod.expected_version
error << mod.v3_module.current_release.version
error << e.message
error_array << error
logger.debug "Error loading module #{mod.full_name} - #{e.inspect}"
end
end
output_array << row
end
end

threads.map(&:join)

output_array.sort_by! { |line| line[0] }
error_array.sort_by! { |line| line[0] } unless error_array.empty?

puts Terminal::Table.new(headings: ["Full Name", "Current Version", "Latest Version", "Out of Date?", "Endorsement", "Superseded by"], rows: output_array)
puts Terminal::Table.new(headings: ["Issue assessing module", "Current", "Latest", "Error"], rows: error_array) unless error_array.empty?
end

def update_puppetfile
Expand Down