Merge pull request #1493 from MikeMcQuaid/audit-version-decrease-fix

audit: fix "version should not decrease" check.
This commit is contained in:
Mike McQuaid 2016-11-13 14:05:59 +00:00 committed by GitHub
commit fc3d586584
2 changed files with 38 additions and 16 deletions

View File

@ -662,26 +662,39 @@ class FormulaAuditor
return if @new_formula return if @new_formula
fv = FormulaVersions.new(formula, max_depth: 10) fv = FormulaVersions.new(formula, max_depth: 10)
no_decrease_attributes = [:revision, :version_scheme] attributes = [:revision, :version_scheme]
attributes = no_decrease_attributes + [:version]
attributes_map = fv.version_attributes_map(attributes, "origin/master") attributes_map = fv.version_attributes_map(attributes, "origin/master")
no_decrease_attributes.each do |attribute| [:stable, :devel].each do |spec|
attributes_for_version = attributes_map[attribute][formula.version] attributes.each do |attribute|
next if attributes_for_version.empty? spec_attribute_map = attributes_map[attribute][spec]
if formula.send(attribute) < attributes_for_version.max next if spec_attribute_map.nil? || spec_attribute_map.empty?
problem "#{attribute} should not decrease"
end
end
versions = attributes_map[:version].values.flatten attributes_for_version = spec_attribute_map[formula.version]
if !versions.empty? && formula.version < versions.max next if attributes_for_version.nil? || attributes_for_version.empty?
problem "version should not decrease"
if formula.send(attribute) < attributes_for_version.max
problem "#{spec} #{attribute} should not decrease"
end
end
spec_version_scheme_map = attributes_map[:version_scheme][spec]
next if spec_version_scheme_map.nil? || spec_version_scheme_map.empty?
max_version_scheme = spec_version_scheme_map.values.flatten.max
max_version = spec_version_scheme_map.select do |_, version_scheme|
version_scheme.first == max_version_scheme
end.keys.max
if max_version && formula.version < max_version
problem "#{spec} version should not decrease"
end
end end
return if formula.revision.zero? return if formula.revision.zero?
if formula.stable if formula.stable
revision_map = attributes_map[:revision] revision_map = attributes_map[:revision][:stable]
if revision_map[formula.stable.version].empty? # check stable spec if revision_map[formula.stable.version].empty? # check stable spec
problem "'revision #{formula.revision}' should be removed" problem "'revision #{formula.revision}' should be removed"
end end

View File

@ -61,19 +61,28 @@ class FormulaVersions
def version_attributes_map(attributes, branch) def version_attributes_map(attributes, branch)
attributes_map = {} attributes_map = {}
return attributes_map if attributes.empty? return attributes_map if attributes.empty?
attributes.each do |attribute| attributes.each do |attribute|
attributes_map[attribute] = Hash.new { |h, k| h[k] = [] } attributes_map[attribute] ||= {}
end end
rev_list(branch) do |rev| rev_list(branch) do |rev|
formula_at_revision(rev) do |f| formula_at_revision(rev) do |f|
attributes.each do |attribute| attributes.each do |attribute|
map = attributes_map[attribute] map = attributes_map[attribute]
map[f.stable.version] << f.send(attribute) if f.stable if f.stable
map[f.devel.version] << f.send(attribute) if f.devel map[:stable] ||= {}
map[:stable][f.stable.version] ||= []
map[:stable][f.stable.version] << f.send(attribute)
end
next unless f.devel
map[:devel] ||= {}
map[:stable][f.devel.version] ||= []
map[:devel][f.devel.version] << f.send(attribute)
end end
end end
end end
attributes_map attributes_map
end end
end end