Merge pull request #8701 from SeekingMeaning/rubocops/gitlab-patches
rubocops/patches: GitHub/GitLab patches should end with .patch
This commit is contained in:
commit
f8f7970802
@ -48,6 +48,20 @@ module RuboCop
|
|||||||
problem "Use a commit hash URL rather than an unstable merge request URL: #{patch_url}"
|
problem "Use a commit hash URL rather than an unstable merge request URL: #{patch_url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{https://github.com/[^/]*/[^/]*/commit/[a-fA-F0-9]*\.diff})
|
||||||
|
problem <<~EOS.chomp
|
||||||
|
GitHub patches should end with .patch, not .diff:
|
||||||
|
#{patch_url}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
if regex_match_group(patch, %r{.*gitlab.*/commit/[a-fA-F0-9]*\.diff})
|
||||||
|
problem <<~EOS.chomp
|
||||||
|
GitLab patches should end with .patch, not .diff:
|
||||||
|
#{patch_url}
|
||||||
|
EOS
|
||||||
|
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) && !patch_url.match?(/\?full_index=\w+$/)
|
if regex_match_group(patch, gh_patch_param_pattern) && !patch_url.match?(/\?full_index=\w+$/)
|
||||||
problem <<~EOS
|
problem <<~EOS
|
||||||
|
|||||||
@ -215,6 +215,8 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
|||||||
"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://github.com/uber/h3/pull/362.patch?full_index=1",
|
||||||
"https://gitlab.gnome.org/GNOME/gitg/-/merge_requests/142.diff",
|
"https://gitlab.gnome.org/GNOME/gitg/-/merge_requests/142.diff",
|
||||||
|
"https://github.com/michaeldv/pit/commit/f64978d.diff?full_index=1",
|
||||||
|
"https://gitlab.gnome.org/GNOME/msitools/commit/248450a.diff",
|
||||||
]
|
]
|
||||||
patch_urls.each do |patch_url|
|
patch_urls.each do |patch_url|
|
||||||
source = <<~RUBY
|
source = <<~RUBY
|
||||||
@ -281,6 +283,26 @@ 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/[^/]*/[^/]*/commit/})
|
||||||
|
[{ message:
|
||||||
|
<<~EOS.chomp,
|
||||||
|
GitHub patches should end with .patch, not .diff:
|
||||||
|
#{patch_url}
|
||||||
|
EOS
|
||||||
|
severity: :convention,
|
||||||
|
line: 5,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
|
elsif patch_url.match?(%r{.*gitlab.*/commit/})
|
||||||
|
[{ message:
|
||||||
|
<<~EOS.chomp,
|
||||||
|
GitLab patches should end with .patch, not .diff:
|
||||||
|
#{patch_url}
|
||||||
|
EOS
|
||||||
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user