From ea10192f8b420a5b3cb2e7b7f24d4714e8a8d548 Mon Sep 17 00:00:00 2001 From: Seeker Date: Fri, 11 Sep 2020 09:07:20 -0700 Subject: [PATCH] rubocops/patches: GitHub/GitLab patches should end with .patch --- Library/Homebrew/rubocops/patches.rb | 14 ++++++++++++ .../Homebrew/test/rubocops/patches_spec.rb | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index 6ed4157c5d..2d893f7d15 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -48,6 +48,20 @@ module RuboCop problem "Use a commit hash URL rather than an unstable merge request URL: #{patch_url}" 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)} if regex_match_group(patch, gh_patch_param_pattern) && !patch_url.match?(/\?full_index=\w+$/) problem <<~EOS diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index 41d24cc512..6dc31fa92f 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -215,6 +215,8 @@ describe RuboCop::Cop::FormulaAudit::Patches do "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", + "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| source = <<~RUBY @@ -281,6 +283,26 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 9, 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 elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}) # rubocop:enable Layout/LineLength