[rubygems/rubygems] Warn for duplicate meta data links

Match order of METADATA_LINK_KEYS to order used by rubygems.org in Links model.
Add missing download_uri key.

https://github.com/rubygems/rubygems/commit/d2922cd6e9
This commit is contained in:
Drew Stevenson 2023-11-30 22:35:33 -06:00 коммит произвёл git
Родитель d7dad64465
Коммит beefce1444
2 изменённых файлов: 55 добавлений и 4 удалений

Просмотреть файл

@ -12,13 +12,14 @@ class Gem::SpecificationPolicy
VALID_URI_PATTERN = %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z} # :nodoc:
METADATA_LINK_KEYS = %w[
bug_tracker_uri
changelog_uri
documentation_uri
homepage_uri
mailing_list_uri
changelog_uri
source_code_uri
documentation_uri
wiki_uri
mailing_list_uri
bug_tracker_uri
download_uri
funding_uri
].freeze # :nodoc:
@ -106,6 +107,8 @@ class Gem::SpecificationPolicy
validate_removed_attributes
validate_unique_links
if @warnings > 0
if strict
error "specification has warnings"
@ -501,6 +504,22 @@ You have specified rake based extension, but rake is not added as dependency. It
WARNING
end
def validate_unique_links
links = @specification.metadata.slice(*METADATA_LINK_KEYS)
grouped = links.group_by {|_key, uri| uri }
grouped.each do |uri, copies|
next unless copies.length > 1
keys = copies.map(&:first).join("\n ")
warning <<~WARNING
You have specified the uri:
#{uri}
for all of the following keys:
#{keys}
Only the first one will be shown on rubygems.org
WARNING
end
end
def warning(statement) # :nodoc:
@warnings += 1

Просмотреть файл

@ -3644,6 +3644,38 @@ Did you mean 'Ruby'?
end
end
def test_metadata_link_validation_warns_for_duplicates
util_setup_validate
Dir.chdir @tempdir do
@m2 = quick_gem "m", "2" do |s|
s.files = %w[lib/code.rb]
s.licenses = "BSD-2-Clause"
s.metadata = {
"source_code_uri" => "http://example.com",
"homepage_uri" => "http://example.com",
"changelog_uri" => "http://example.com/changelog",
}
end
use_ui @ui do
@m2.validate
end
expected = <<~EXPECTED
#{w}: You have specified the uri:
http://example.com
for all of the following keys:
homepage_uri
source_code_uri
Only the first one will be shown on rubygems.org
#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED
assert_equal expected, @ui.error, "warning"
end
end
def test_metadata_specs
@m1 = quick_gem "m", "1" do |s|
s.files = %w[lib/code.rb]