audit: Port patches audit code to a rubocop
This commit is contained in:
parent
c26c9204fa
commit
43cec10000
@ -630,7 +630,6 @@ class FormulaAuditor
|
|||||||
end
|
end
|
||||||
|
|
||||||
next if spec.patches.empty?
|
next if spec.patches.empty?
|
||||||
spec.patches.each { |p| patch_problems(p) if p.external? }
|
|
||||||
next unless @new_formula
|
next unless @new_formula
|
||||||
problem "New formulae should not require patches to build. Patches should be submitted and accepted upstream first."
|
problem "New formulae should not require patches to build. Patches should be submitted and accepted upstream first."
|
||||||
end
|
end
|
||||||
@ -786,36 +785,6 @@ class FormulaAuditor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def patch_problems(patch)
|
|
||||||
case patch.url
|
|
||||||
when %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}
|
|
||||||
unless patch.url =~ /\?full_index=\w+$/
|
|
||||||
problem <<-EOS.undent
|
|
||||||
GitHub patches should use the full_index parameter:
|
|
||||||
#{patch.url}?full_index=1
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
when /raw\.github\.com/, %r{gist\.github\.com/raw}, %r{gist\.github\.com/.+/raw},
|
|
||||||
%r{gist\.githubusercontent\.com/.+/raw}
|
|
||||||
unless patch.url =~ /[a-fA-F0-9]{40}/
|
|
||||||
problem "GitHub/Gist patches should specify a revision:\n#{patch.url}"
|
|
||||||
end
|
|
||||||
when %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
|
|
||||||
problem <<-EOS.undent
|
|
||||||
use GitHub pull request URLs:
|
|
||||||
https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/pull/#{Regexp.last_match(3)}.patch?full_index=1
|
|
||||||
Rather than patch-diff:
|
|
||||||
#{patch.url}
|
|
||||||
EOS
|
|
||||||
when %r{macports/trunk}
|
|
||||||
problem "MacPorts patches should specify a revision instead of trunk:\n#{patch.url}"
|
|
||||||
when %r{^http://trac\.macports\.org}
|
|
||||||
problem "Patches from MacPorts Trac should be https://, not http:\n#{patch.url}"
|
|
||||||
when %r{^http://bugs\.debian\.org}
|
|
||||||
problem "Patches from Debian should be https://, not http:\n#{patch.url}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def audit_text
|
def audit_text
|
||||||
bin_names = Set.new
|
bin_names = Set.new
|
||||||
bin_names << formula.name
|
bin_names << formula.name
|
||||||
|
|||||||
@ -380,6 +380,40 @@ module RuboCop
|
|||||||
add_offense(@offensive_node, @offense_source_range, msg)
|
add_offense(@offensive_node, @offense_source_range, msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def patch_problems(patch)
|
||||||
|
patch_url = string_content(patch)
|
||||||
|
gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/},
|
||||||
|
%r{gist\.github\.com/raw},
|
||||||
|
%r{gist\.github\.com/.+/raw},
|
||||||
|
%r{gist\.githubusercontent\.com/.+/raw}])
|
||||||
|
if regex_match_group(patch, gh_patch_patterns)
|
||||||
|
unless patch_url =~ /[a-fA-F0-9]{40}/
|
||||||
|
problem "GitHub/Gist patches should specify a revision:\n#{patch_url}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
gh_patch_diff_pattern = %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
|
||||||
|
if match_obj = regex_match_group(patch, gh_patch_diff_pattern)
|
||||||
|
problem <<-EOS.undent
|
||||||
|
use GitHub pull request URLs:
|
||||||
|
https://github.com/#{match_obj[1]}/#{match_obj[2]}/pull/#{match_ojb[3]}.patch
|
||||||
|
Rather than patch-diff:
|
||||||
|
#{patch_url}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{macports/trunk})
|
||||||
|
problem "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{^http://trac\.macports\.org})
|
||||||
|
problem "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}"
|
||||||
|
end
|
||||||
|
|
||||||
|
return unless regex_match_group(patch, %r{^http://bugs\.debian\.org})
|
||||||
|
problem "Patches from Debian should be https://, not http:\n#{patch_url}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def formula_class?(node)
|
def formula_class?(node)
|
||||||
|
|||||||
@ -13,39 +13,16 @@ module RuboCop
|
|||||||
problem "Use the patch DSL instead of defining a 'patches' method"
|
problem "Use the patch DSL instead of defining a 'patches' method"
|
||||||
legacy_patches.each { |p| patch_problems(p) }
|
legacy_patches.each { |p| patch_problems(p) }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def patch_problems(patch)
|
class ExternalPatches < FormulaCop
|
||||||
patch_url = string_content(patch)
|
def audit_formula(_node, _class_node, _parent_class_node, body)
|
||||||
gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/},
|
patches = find_all_blocks(body, :patch)
|
||||||
%r{gist\.github\.com/raw},
|
patches.each do |patch_block|
|
||||||
%r{gist\.github\.com/.+/raw},
|
url_node = find_node_method_by_name(patch_block, :url)
|
||||||
%r{gist\.githubusercontent\.com/.+/raw}])
|
url_string = parameters(url_node).first
|
||||||
if regex_match_group(patch, gh_patch_patterns)
|
patch_problems(url_string)
|
||||||
unless patch_url =~ /[a-fA-F0-9]{40}/
|
|
||||||
problem "GitHub/Gist patches should specify a revision:\n#{patch_url}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
gh_patch_diff_pattern = %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
|
|
||||||
if match_obj = regex_match_group(patch, gh_patch_diff_pattern)
|
|
||||||
problem <<-EOS.undent
|
|
||||||
use GitHub pull request URLs:
|
|
||||||
https://github.com/#{match_obj[1]}/#{match_obj[2]}/pull/#{match_ojb[3]}.patch
|
|
||||||
Rather than patch-diff:
|
|
||||||
#{patch_url}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
if regex_match_group(patch, %r{macports/trunk})
|
|
||||||
problem "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if regex_match_group(patch, %r{^http://trac\.macports\.org})
|
|
||||||
problem "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}"
|
|
||||||
end
|
|
||||||
|
|
||||||
return unless regex_match_group(patch, %r{^http://bugs\.debian\.org})
|
|
||||||
problem "Patches from Debian should be https://, not http:\n#{patch_url}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user