Merge pull request #19880 from Moisan/audit_bitbucket_patch

patches audit: bitbucket patches should use api
This commit is contained in:
Sean Molenaar 2025-05-15 12:45:30 +00:00 committed by GitHub
commit 107120e4d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -59,6 +59,15 @@ module RuboCop
problem "GitHub patches should end with .patch, not .diff: #{patch_url}"
end
bitbucket_regex = %r{bitbucket\.org/([^/]+)/([^/]+)/commits/([a-f0-9]+)/raw}i
if regex_match_group(patch_url_node, bitbucket_regex)
owner, repo, commit = patch_url_node.source.match(bitbucket_regex).captures
correct_url = "https://api.bitbucket.org/2.0/repositories/#{owner}/#{repo}/diff/#{commit}"
problem "Bitbucket patches should use the api url: #{correct_url}" do |corrector|
corrector.replace(patch_url_node.source_range, %Q("#{correct_url}"))
end
end
# Only .diff passes `--full-index` to `git diff` and there is no documented way
# to get .patch to behave the same for GitLab.
if regex_match_group(patch_url_node, %r{.*gitlab.*/commit/[a-fA-F0-9]*\.patch})

View File

@ -39,6 +39,7 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Patches do
"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/commit/2c916b1a7999a050ac4970c3415ff8f91cd487aa.patch",
"https://bitbucket.org/multicoreware/x265_git/commits/b354c009a60bcd6d7fc04014e200a1ee9c45c167/raw",
]
patch_urls.each do |patch_url|
source = <<~EOS
@ -78,6 +79,12 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Patches do
expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:)
FormulaAudit/Patches: GitHub patches should use the full_index parameter: #{patch_url}?full_index=1
EOS
elsif patch_url.start_with?("https://bitbucket.org/")
commit = "b354c009a60bcd6d7fc04014e200a1ee9c45c167"
fixed_url = "https://api.bitbucket.org/2.0/repositories/multicoreware/x265_git/diff/#{commit}"
expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:)
FormulaAudit/Patches: Bitbucket patches should use the api url: #{fixed_url}
EOS
end
expected_offense.zip([inspect_source(source).last]).each do |expected, actual|
expect(actual.message).to eq(expected[:message])