|
|
@ -9,7 +9,8 @@ class UpdatesCLI < Thor
|
|
|
|
super
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
desc 'check [doc]...', 'Check for outdated documentations'
|
|
|
|
desc 'check [--verbose] [doc]...', 'Check for outdated documentations'
|
|
|
|
|
|
|
|
option :verbose, :type => :boolean
|
|
|
|
def check(*names)
|
|
|
|
def check(*names)
|
|
|
|
# Convert names to a list of Scraper instances
|
|
|
|
# Convert names to a list of Scraper instances
|
|
|
|
# Versions are omitted, if v10 is outdated than v8 is aswell
|
|
|
|
# Versions are omitted, if v10 is outdated than v8 is aswell
|
|
|
@ -27,13 +28,14 @@ class UpdatesCLI < Thor
|
|
|
|
result
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
outdated = results.select {|result| result.is_a?(Hash) && result[:is_outdated]}
|
|
|
|
valid_results = results.select {|result| result.is_a?(Hash)}
|
|
|
|
return if outdated.empty?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("Outdated documentations (#{outdated.length}):")
|
|
|
|
up_to_date_results = valid_results.select {|result| !result[:is_outdated]}
|
|
|
|
outdated.each do |result|
|
|
|
|
outdated_results = valid_results.select {|result| result[:is_outdated]}
|
|
|
|
logger.info("#{result[:name]}: #{result[:current_version]} -> #{result[:latest_version]}")
|
|
|
|
|
|
|
|
end
|
|
|
|
log_results('Up-to-date', up_to_date_results) if options[:verbose] and !up_to_date_results.empty?
|
|
|
|
|
|
|
|
logger.info("") if options[:verbose] and !up_to_date_results.empty? and !outdated_results.empty?
|
|
|
|
|
|
|
|
log_results('Outdated', outdated_results) unless outdated_results.empty?
|
|
|
|
rescue Docs::DocNotFound => error
|
|
|
|
rescue Docs::DocNotFound => error
|
|
|
|
logger.error(error)
|
|
|
|
logger.error(error)
|
|
|
|
logger.info('Run "thor docs:list" to see the list of docs.')
|
|
|
|
logger.info('Run "thor docs:list" to see the list of docs.')
|
|
|
@ -42,33 +44,48 @@ class UpdatesCLI < Thor
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
def check_doc(doc)
|
|
|
|
def check_doc(doc)
|
|
|
|
# Scraper versions are always sorted from new to old
|
|
|
|
# Newer scraper versions always come before older scraper versions
|
|
|
|
# Therefore, the first item's release value is the latest current scraper version
|
|
|
|
# Therefore, the first item's release value is the latest current scraper version
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# For example, a scraper could scrape 3 versions: 10, 11 and 12
|
|
|
|
# For example, a scraper could scrape 3 versions: 10, 11 and 12
|
|
|
|
# doc.versions.first would be the scraper for version 12 if the scraper is written like all the other scrapers are
|
|
|
|
# doc.versions.first would be the scraper for version 12
|
|
|
|
instance = doc.versions.first.new
|
|
|
|
instance = doc.versions.first.new
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil unless instance.class.method_defined?(:options)
|
|
|
|
|
|
|
|
|
|
|
|
current_version = instance.options[:release]
|
|
|
|
current_version = instance.options[:release]
|
|
|
|
return nil if current_version.nil?
|
|
|
|
return nil if current_version.nil?
|
|
|
|
|
|
|
|
|
|
|
|
latest_version = instance.get_latest_version
|
|
|
|
logger.debug("Checking #{doc.name}")
|
|
|
|
return nil if latest_version.nil?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
instance.get_latest_version do |latest_version|
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: doc.name,
|
|
|
|
name: doc.name,
|
|
|
|
current_version: current_version,
|
|
|
|
current_version: current_version,
|
|
|
|
latest_version: latest_version,
|
|
|
|
latest_version: latest_version,
|
|
|
|
is_outdated: instance.is_outdated(current_version, latest_version)
|
|
|
|
is_outdated: instance.is_outdated(current_version, latest_version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
rescue NotImplementedError
|
|
|
|
rescue NotImplementedError
|
|
|
|
logger.warn("Can't check #{doc.name}, get_latest_version is not implemented")
|
|
|
|
logger.warn("Couldn't check #{doc.name}, get_latest_version is not implemented")
|
|
|
|
rescue => error
|
|
|
|
rescue
|
|
|
|
logger.error("Error while checking #{doc.name}: #{error}")
|
|
|
|
logger.error("Error while checking #{doc.name}")
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log_results(label, results)
|
|
|
|
|
|
|
|
logger.info("#{label} documentations (#{results.length}):")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results.each do |result|
|
|
|
|
|
|
|
|
logger.info("#{result[:name]}: #{result[:current_version]} -> #{result[:latest_version]}")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def logger
|
|
|
|
def logger
|
|
|
|
@logger ||= Logger.new($stdout).tap do |logger|
|
|
|
|
@logger ||= Logger.new($stdout).tap do |logger|
|
|
|
|
|
|
|
|
logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
|
|
|
|
logger.formatter = proc do |severity, datetime, progname, msg|
|
|
|
|
logger.formatter = proc do |severity, datetime, progname, msg|
|
|
|
|
prefix = severity != "INFO" ? "[#{severity}] " : ""
|
|
|
|
prefix = severity != "INFO" ? "[#{severity}] " : ""
|
|
|
|
"#{prefix}#{msg}\n"
|
|
|
|
"#{prefix}#{msg}\n"
|
|
|
|