[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:
parent
d7dad64465
commit
beefce1444
@ -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:
|
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[
|
METADATA_LINK_KEYS = %w[
|
||||||
bug_tracker_uri
|
|
||||||
changelog_uri
|
|
||||||
documentation_uri
|
|
||||||
homepage_uri
|
homepage_uri
|
||||||
mailing_list_uri
|
changelog_uri
|
||||||
source_code_uri
|
source_code_uri
|
||||||
|
documentation_uri
|
||||||
wiki_uri
|
wiki_uri
|
||||||
|
mailing_list_uri
|
||||||
|
bug_tracker_uri
|
||||||
|
download_uri
|
||||||
funding_uri
|
funding_uri
|
||||||
].freeze # :nodoc:
|
].freeze # :nodoc:
|
||||||
|
|
||||||
@ -106,6 +107,8 @@ class Gem::SpecificationPolicy
|
|||||||
|
|
||||||
validate_removed_attributes
|
validate_removed_attributes
|
||||||
|
|
||||||
|
validate_unique_links
|
||||||
|
|
||||||
if @warnings > 0
|
if @warnings > 0
|
||||||
if strict
|
if strict
|
||||||
error "specification has warnings"
|
error "specification has warnings"
|
||||||
@ -501,6 +504,22 @@ You have specified rake based extension, but rake is not added as dependency. It
|
|||||||
WARNING
|
WARNING
|
||||||
end
|
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:
|
def warning(statement) # :nodoc:
|
||||||
@warnings += 1
|
@warnings += 1
|
||||||
|
|
||||||
|
@ -3644,6 +3644,38 @@ Did you mean 'Ruby'?
|
|||||||
end
|
end
|
||||||
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
|
def test_metadata_specs
|
||||||
@m1 = quick_gem "m", "1" do |s|
|
@m1 = quick_gem "m", "1" do |s|
|
||||||
s.files = %w[lib/code.rb]
|
s.files = %w[lib/code.rb]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user