diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index c3ff5c8e09..16b2e05ba9 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -37,9 +37,18 @@ module RuboCop return if formula_tap != "homebrew-core" # Check for binary URLs - audit_urls(urls, /(darwin|macos|osx)/i) do |match, url| + binary_package_pattern = /(darwin|macos|osx)/i + github_pattern = %r{^https://github\.com/[\w-]+/[\w.-]+/(.*)$}i + audit_urls(urls, binary_package_pattern) do |match, url| next if T.must(@formula_name).include?(match.to_s.downcase) next if url.match?(/.(patch|diff)(\?full_index=1)?$/) + next if url.match(github_pattern)&.then do |match_data| + # For GitHub URLs, the username and repository name have no + # bearing on whether a file is a binary package. We'll extract the + # remainder of the URL and match against the binary pattern. + # See: https://github.com/Homebrew/brew/pull/23236 + !match_data[1].match?(binary_package_pattern) + end next if tap_style_exception? :not_a_binary_url_prefix_allowlist next if tap_style_exception? :binary_bootstrap_formula_urls_allowlist diff --git a/Library/Homebrew/test/rubocops/urls_spec.rb b/Library/Homebrew/test/rubocops/urls_spec.rb index 6fe3c6c083..c76bcc7130 100644 --- a/Library/Homebrew/test/rubocops/urls_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_spec.rb @@ -159,6 +159,12 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Urls do "not a source archive; homebrew/core is source-only.", "col" => 2, "formula_tap" => "homebrew-core", + }, { + "url" => "https://github.com/foo/bar/archive/refs/tags/darwin.tar.gz", + "msg" => "https://github.com/foo/bar/archive/refs/tags/darwin.tar.gz looks like a binary package, " \ + "not a source archive; homebrew/core is source-only.", + "col" => 2, + "formula_tap" => "homebrew-core", }, { "url" => "cvs://brew.sh/foo/bar", "msg" => "Use of the \"cvs://\" scheme is deprecated, pass `using: :cvs` instead", @@ -302,6 +308,17 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Urls do expect(inspect_source(source)).to eq([]) end + + it "does not report an offense based on the username or repo name of a GitHub URL" do + source = <<~RUBY + class Foo < Formula + desc "foo" + url "https://github.com/scriptingosx/cool-darwin-app/archive/refs/tags/v0.1.1.tar.gz" + end + RUBY + + expect(inspect_source(source)).to eq([]) + end end context "when auditing Apache URLs" do