Merge pull request #1493 from MikeMcQuaid/audit-version-decrease-fix
audit: fix "version should not decrease" check.
This commit is contained in:
commit
fc3d586584
@ -662,26 +662,39 @@ class FormulaAuditor
|
||||
return if @new_formula
|
||||
|
||||
fv = FormulaVersions.new(formula, max_depth: 10)
|
||||
no_decrease_attributes = [:revision, :version_scheme]
|
||||
attributes = no_decrease_attributes + [:version]
|
||||
attributes = [:revision, :version_scheme]
|
||||
|
||||
attributes_map = fv.version_attributes_map(attributes, "origin/master")
|
||||
|
||||
no_decrease_attributes.each do |attribute|
|
||||
attributes_for_version = attributes_map[attribute][formula.version]
|
||||
next if attributes_for_version.empty?
|
||||
if formula.send(attribute) < attributes_for_version.max
|
||||
problem "#{attribute} should not decrease"
|
||||
end
|
||||
end
|
||||
[:stable, :devel].each do |spec|
|
||||
attributes.each do |attribute|
|
||||
spec_attribute_map = attributes_map[attribute][spec]
|
||||
next if spec_attribute_map.nil? || spec_attribute_map.empty?
|
||||
|
||||
versions = attributes_map[:version].values.flatten
|
||||
if !versions.empty? && formula.version < versions.max
|
||||
problem "version should not decrease"
|
||||
attributes_for_version = spec_attribute_map[formula.version]
|
||||
next if attributes_for_version.nil? || attributes_for_version.empty?
|
||||
|
||||
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
|
||||
|
||||
return if formula.revision.zero?
|
||||
if formula.stable
|
||||
revision_map = attributes_map[:revision]
|
||||
revision_map = attributes_map[:revision][:stable]
|
||||
if revision_map[formula.stable.version].empty? # check stable spec
|
||||
problem "'revision #{formula.revision}' should be removed"
|
||||
end
|
||||
|
||||
@ -61,19 +61,28 @@ class FormulaVersions
|
||||
def version_attributes_map(attributes, branch)
|
||||
attributes_map = {}
|
||||
return attributes_map if attributes.empty?
|
||||
|
||||
attributes.each do |attribute|
|
||||
attributes_map[attribute] = Hash.new { |h, k| h[k] = [] }
|
||||
attributes_map[attribute] ||= {}
|
||||
end
|
||||
|
||||
rev_list(branch) do |rev|
|
||||
formula_at_revision(rev) do |f|
|
||||
attributes.each do |attribute|
|
||||
map = attributes_map[attribute]
|
||||
map[f.stable.version] << f.send(attribute) if f.stable
|
||||
map[f.devel.version] << f.send(attribute) if f.devel
|
||||
if f.stable
|
||||
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
|
||||
|
||||
attributes_map
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user