Merge pull request #8075 from dtrodrigues/no-pr-url
style: don't allow patches to be PR/MR urls
This commit is contained in:
commit
41c6a48936
@ -38,6 +38,15 @@ module RuboCop
|
|||||||
|
|
||||||
def patch_problems(patch)
|
def patch_problems(patch)
|
||||||
patch_url = string_content(patch)
|
patch_url = string_content(patch)
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{https://github.com/[^/]*/[^/]*/pull})
|
||||||
|
problem "Use a commit hash URL rather than an unstable pull request URL: #{patch_url}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{.*gitlab.*/merge_request.*})
|
||||||
|
problem "Use a commit hash URL rather than an unstable merge request URL: #{patch_url}"
|
||||||
|
end
|
||||||
|
|
||||||
gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}
|
gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}
|
||||||
if regex_match_group(patch, gh_patch_param_pattern)
|
if regex_match_group(patch, gh_patch_param_pattern)
|
||||||
unless patch_url.match?(/\?full_index=\w+$/)
|
unless patch_url.match?(/\?full_index=\w+$/)
|
||||||
@ -64,13 +73,8 @@ module RuboCop
|
|||||||
|
|
||||||
gh_patch_diff_pattern =
|
gh_patch_diff_pattern =
|
||||||
%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
|
%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
|
||||||
if match_obj = regex_match_group(patch, gh_patch_diff_pattern)
|
if regex_match_group(patch, gh_patch_diff_pattern)
|
||||||
problem <<~EOS
|
problem "Use a commit hash URL rather than patch-diff: #{patch_url}"
|
||||||
use GitHub pull request URLs:
|
|
||||||
https://github.com/#{match_obj[1]}/#{match_obj[2]}/pull/#{match_obj[3]}.patch?full_index=1
|
|
||||||
Rather than patch-diff:
|
|
||||||
#{patch_url}
|
|
||||||
EOS
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if regex_match_group(patch, %r{macports/trunk})
|
if regex_match_group(patch, %r{macports/trunk})
|
||||||
|
@ -34,7 +34,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
|||||||
"http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
|
"http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
|
||||||
"http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
|
"http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
|
||||||
"https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
|
"https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
|
||||||
"https://github.com/dlang/dub/pull/1221.patch",
|
"https://github.com/dlang/dub/commit/2c916b1a7999a050ac4970c3415ff8f91cd487aa.patch",
|
||||||
]
|
]
|
||||||
patch_urls.each do |patch_url|
|
patch_urls.each do |patch_url|
|
||||||
source = <<~EOS
|
source = <<~EOS
|
||||||
@ -91,13 +91,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
|||||||
# rubocop:disable Layout/LineLength
|
# rubocop:disable Layout/LineLength
|
||||||
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
||||||
# rubocop:enable Layout/LineLength
|
# rubocop:enable Layout/LineLength
|
||||||
[{ message:
|
[{ message: "Use a commit hash URL rather than patch-diff: #{patch_url}",
|
||||||
<<~EOS,
|
|
||||||
use GitHub pull request URLs:
|
|
||||||
https://github.com/foo/foo-bar/pull/100.patch?full_index=1
|
|
||||||
Rather than patch-diff:
|
|
||||||
https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
severity: :convention,
|
||||||
line: 5,
|
line: 5,
|
||||||
column: 5,
|
column: 5,
|
||||||
@ -218,6 +212,8 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
|||||||
"http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
|
"http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
|
||||||
"http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
|
"http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
|
||||||
"https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
|
"https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
|
||||||
|
"https://github.com/uber/h3/pull/362.patch?full_index=1",
|
||||||
|
"https://gitlab.gnome.org/GNOME/gitg/-/merge_requests/142.diff",
|
||||||
]
|
]
|
||||||
patch_urls.each do |patch_url|
|
patch_urls.each do |patch_url|
|
||||||
source = <<~RUBY
|
source = <<~RUBY
|
||||||
@ -272,16 +268,22 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
|||||||
line: 5,
|
line: 5,
|
||||||
column: 9,
|
column: 9,
|
||||||
source: source }]
|
source: source }]
|
||||||
|
elsif patch_url.match?(%r{https://github.com/[^/]*/[^/]*/pull})
|
||||||
|
[{ message: "Use a commit hash URL rather than an unstable pull request URL: #{patch_url}",
|
||||||
|
severity: :convention,
|
||||||
|
line: 5,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
|
elsif patch_url.match?(%r{.*gitlab.*/merge_request.*})
|
||||||
|
[{ message: "Use a commit hash URL rather than an unstable merge request URL: #{patch_url}",
|
||||||
|
severity: :convention,
|
||||||
|
line: 5,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
# rubocop:disable Layout/LineLength
|
# rubocop:disable Layout/LineLength
|
||||||
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
|
||||||
# rubocop:enable Layout/LineLength
|
# rubocop:enable Layout/LineLength
|
||||||
[{ message:
|
[{ message: "Use a commit hash URL rather than patch-diff: #{patch_url}",
|
||||||
<<~EOS,
|
|
||||||
use GitHub pull request URLs:
|
|
||||||
https://github.com/foo/foo-bar/pull/100.patch?full_index=1
|
|
||||||
Rather than patch-diff:
|
|
||||||
https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
severity: :convention,
|
||||||
line: 5,
|
line: 5,
|
||||||
column: 9,
|
column: 9,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user