thor updates:check group major/minor updates

pull/1456/head
Simon Legner 4 years ago
parent ae82da789e
commit cb6865b0a8

@ -184,7 +184,7 @@ module Docs
raise NotImplementedError raise NotImplementedError
end end
# Returns whether or not this scraper is outdated. # Returns whether or not this scraper is outdated ("Outdated major version", "Outdated minor version" or 'Up-to-date').
# #
# The default implementation assumes the documentation uses a semver(-like) approach when it comes to versions. # The default implementation assumes the documentation uses a semver(-like) approach when it comes to versions.
# Patch updates are ignored because there are usually little to no documentation changes in bug-fix-only releases. # Patch updates are ignored because there are usually little to no documentation changes in bug-fix-only releases.
@ -195,18 +195,19 @@ module Docs
# 1 -> 2 = outdated # 1 -> 2 = outdated
# 1.1 -> 1.2 = outdated # 1.1 -> 1.2 = outdated
# 1.1.1 -> 1.1.2 = not outdated # 1.1.1 -> 1.1.2 = not outdated
def is_outdated(scraper_version, latest_version) def outdated_state(scraper_version, latest_version)
scraper_parts = scraper_version.to_s.split(/[-.]/).map(&:to_i) scraper_parts = scraper_version.to_s.split(/[-.]/).map(&:to_i)
latest_parts = latest_version.to_s.split(/[-.]/).map(&:to_i) latest_parts = latest_version.to_s.split(/[-.]/).map(&:to_i)
# Only check the first two parts, the third part is for patch updates # Only check the first two parts, the third part is for patch updates
[0, 1].each do |i| [0, 1].each do |i|
break if i >= scraper_parts.length or i >= latest_parts.length break if i >= scraper_parts.length or i >= latest_parts.length
return true if latest_parts[i] > scraper_parts[i] return 'Outdated major version' if i == 0 and latest_parts[i] > scraper_parts[i]
return false if latest_parts[i] < scraper_parts[i] return 'Outdated minor version' if i == 1 and latest_parts[i] > scraper_parts[i]
return 'Up-to-date' if latest_parts[i] < scraper_parts[i]
end end
false 'Up-to-date'
end end
private private

@ -68,7 +68,7 @@ class UpdatesCLI < Thor
name: doc.name, name: doc.name,
scraper_version: format_version(scraper_version), scraper_version: format_version(scraper_version),
latest_version: format_version(latest_version), latest_version: format_version(latest_version),
is_outdated: instance.is_outdated(scraper_version, latest_version) outdated_state: instance.outdated_state(scraper_version, latest_version)
} }
rescue NotImplementedError rescue NotImplementedError
logger.warn("Couldn't check #{doc.name}, get_latest_version is not implemented") logger.warn("Couldn't check #{doc.name}, get_latest_version is not implemented")
@ -95,28 +95,27 @@ class UpdatesCLI < Thor
end end
def process_results(results) def process_results(results)
successful_results = results.select {|result| result.key?(:is_outdated)} successful_results = results.select {|result| result.key?(:outdated_state)}
grouped_results = successful_results.group_by {|result| result[:outdated_state]}
failed_results = results.select {|result| result.key?(:error)} failed_results = results.select {|result| result.key?(:error)}
up_to_date_results = successful_results.select {|result| !result[:is_outdated]} log_results(grouped_results, failed_results)
outdated_results = successful_results.select {|result| result[:is_outdated]} upload_results(grouped_results, failed_results) if options[:upload]
log_results(outdated_results, up_to_date_results, failed_results)
upload_results(outdated_results, up_to_date_results, failed_results) if options[:upload]
end end
# #
# Result logging methods # Result logging methods
# #
def log_results(outdated_results, up_to_date_results, failed_results) def log_results(grouped_results, failed_results)
if options[:markdown] if options[:markdown]
puts all_results_to_markdown(outdated_results, up_to_date_results, failed_results) puts all_results_to_markdown(grouped_results, failed_results)
return return
end end
log_failed_results(failed_results) unless failed_results.empty? log_failed_results(failed_results) unless failed_results.empty?
log_successful_results('Up-to-date', up_to_date_results) unless up_to_date_results.empty? grouped_results.each do |label, results|
log_successful_results('Outdated', outdated_results) unless outdated_results.empty? log_successful_results(label, results)
end
end end
def log_successful_results(label, results) def log_successful_results(label, results)
@ -141,7 +140,7 @@ class UpdatesCLI < Thor
# Upload methods # Upload methods
# #
def upload_results(outdated_results, up_to_date_results, failed_results) def upload_results(grouped_results, failed_results)
# We can't create issues without a GitHub token # We can't create issues without a GitHub token
unless options.key?(:github_token) unless options.key?(:github_token)
logger.error("Please specify a GitHub token with the public_repo permission for #{UPLOAD_USER} with the --github-token parameter") logger.error("Please specify a GitHub token with the public_repo permission for #{UPLOAD_USER} with the --github-token parameter")
@ -163,7 +162,7 @@ class UpdatesCLI < Thor
issue = { issue = {
title: "Documentation versions report for #{Date.today.strftime('%B %Y')}", title: "Documentation versions report for #{Date.today.strftime('%B %Y')}",
body: all_results_to_markdown(outdated_results, up_to_date_results, failed_results) body: all_results_to_markdown(grouped_results, failed_results)
} }
created_issue = github_post("/repos/#{UPLOAD_REPO}/issues", issue) created_issue = github_post("/repos/#{UPLOAD_REPO}/issues", issue)
@ -197,14 +196,14 @@ class UpdatesCLI < Thor
end end
end end
def all_results_to_markdown(outdated_results, up_to_date_results, failed_results) def all_results_to_markdown(grouped_results, failed_results)
results = [ all_results = []
successful_results_to_markdown('Outdated', outdated_results), grouped_results.each do |label, results|
successful_results_to_markdown('Up-to-date', up_to_date_results), all_results.push(successful_results_to_markdown(label, results))
failed_results_to_markdown(failed_results) end
] all_results.push(failed_results_to_markdown(failed_results))
results_str = results.select {|result| !result.nil?}.join("\n\n") results_str = all_results.select {|result| !result.nil?}.join("\n\n")
travis_str = ENV['TRAVIS'].nil? ? '' : "\n\nThis issue was created by Travis CI build [##{ENV['TRAVIS_BUILD_NUMBER']}](#{ENV['TRAVIS_BUILD_WEB_URL']})." travis_str = ENV['TRAVIS'].nil? ? '' : "\n\nThis issue was created by Travis CI build [##{ENV['TRAVIS_BUILD_NUMBER']}](#{ENV['TRAVIS_BUILD_WEB_URL']})."
body = <<-MARKDOWN body = <<-MARKDOWN
@ -216,10 +215,6 @@ Maintainers can close this issue when all documentations are up-to-date. The iss
## Results ## Results
The #{outdated_results.length + up_to_date_results.length + failed_results.length} documentations are divided as follows:
- #{outdated_results.length} that #{outdated_results.length == 1 ? 'is' : 'are'} outdated
- #{up_to_date_results.length} that #{up_to_date_results.length == 1 ? 'is' : 'are'} up-to-date (patch updates are ignored)
- #{failed_results.length} that could not be checked
MARKDOWN MARKDOWN
body.strip + "\n\n" + results_str body.strip + "\n\n" + results_str
end end

@ -390,16 +390,16 @@ class DocsDocTest < MiniTest::Spec
it "compares versions" do it "compares versions" do
instance = doc.versions.first.new instance = doc.versions.first.new
assert !instance.is_outdated('1', '1') assert_equal 'Up-to-date', instance.outdated_state('1', '1')
assert !instance.is_outdated('1.2', '1.2') assert_equal 'Up-to-date', instance.outdated_state('1.2', '1.2')
assert !instance.is_outdated('1.2.2', '1.2.2') assert_equal 'Up-to-date', instance.outdated_state('1.2.2', '1.2.2')
assert !instance.is_outdated('1.2.2', '1.2.3') assert_equal 'Up-to-date', instance.outdated_state('1.2.2', '1.2.3')
assert instance.is_outdated('1', '2') assert_equal "Outdated major version", instance.outdated_state('1', '2')
assert instance.is_outdated('1.2', '1.3') assert_equal "Outdated minor version", instance.outdated_state('1.2', '1.3')
assert instance.is_outdated('9', '10') assert_equal "Outdated major version", instance.outdated_state('9', '10')
assert instance.is_outdated('99', '101') assert_equal "Outdated major version", instance.outdated_state('99', '101')
assert !instance.is_outdated('2006-01-02', '2006-01-03') assert_equal 'Up-to-date', instance.outdated_state('2006-01-02', '2006-01-03')
assert instance.is_outdated('2006-01-02', '2006-02-03') assert_equal "Outdated minor version", instance.outdated_state('2006-01-02', '2006-02-03')
end end
end end
end end

Loading…
Cancel
Save