From 7a2483728c18e9cfb45e4b3f079687ec5a8e1503 Mon Sep 17 00:00:00 2001 From: Dustin Rodrigues Date: Fri, 24 Jul 2020 20:49:26 -0400 Subject: [PATCH] style: don't allow PR/MR urls for patches --- Library/Homebrew/rubocops/patches.rb | 18 +++++++---- .../Homebrew/test/rubocops/patches_spec.rb | 32 ++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index 13cffc6dca..25afeb601c 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -38,6 +38,15 @@ module RuboCop def patch_problems(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)} if regex_match_group(patch, gh_patch_param_pattern) unless patch_url.match?(/\?full_index=\w+$/) @@ -64,13 +73,8 @@ module RuboCop 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 - 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 + if regex_match_group(patch, gh_patch_diff_pattern) + problem "Use a commit hash URL rather than patch-diff: #{patch_url}" end if regex_match_group(patch, %r{macports/trunk}) diff --git a/Library/Homebrew/test/rubocops/patches_spec.rb b/Library/Homebrew/test/rubocops/patches_spec.rb index 0209a6a566..f1bbc3d37e 100644 --- a/Library/Homebrew/test/rubocops/patches_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_spec.rb @@ -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://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://github.com/dlang/dub/pull/1221.patch", + "https://github.com/dlang/dub/commit/2c916b1a7999a050ac4970c3415ff8f91cd487aa.patch", ] patch_urls.each do |patch_url| source = <<~EOS @@ -91,13 +91,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do # rubocop:disable Layout/LineLength elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}) # rubocop:enable Layout/LineLength - [{ message: - <<~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 + [{ message: "Use a commit hash URL rather than patch-diff: #{patch_url}", severity: :convention, line: 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://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://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| source = <<~RUBY @@ -272,16 +268,22 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 5, column: 9, 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 elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}) # rubocop:enable Layout/LineLength - [{ message: - <<~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 + [{ message: "Use a commit hash URL rather than patch-diff: #{patch_url}", severity: :convention, line: 5, column: 9,