File tree Expand file tree Collapse file tree 2 files changed +55
-4
lines changed
Expand file tree Collapse file tree 2 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,14 @@ class Gem::SpecificationPolicy
1212 VALID_URI_PATTERN = %r{\A https?:\/ \/ ([^\s :@]+:[^\s :@]*@)?[A-Za-z\d \- ]+(\. [A-Za-z\d \- ]+)+\. ?(:\d {1,5})?([\/ ?]\S *)?\z } # :nodoc:
1313
1414 METADATA_LINK_KEYS = %w[
15- bug_tracker_uri
16- changelog_uri
17- documentation_uri
1815 homepage_uri
19- mailing_list_uri
16+ changelog_uri
2017 source_code_uri
18+ documentation_uri
2119 wiki_uri
20+ mailing_list_uri
21+ bug_tracker_uri
22+ download_uri
2223 funding_uri
2324 ] . freeze # :nodoc:
2425
@@ -106,6 +107,8 @@ def validate_optional(strict)
106107
107108 validate_removed_attributes
108109
110+ validate_unique_links
111+
109112 if @warnings > 0
110113 if strict
111114 error "specification has warnings"
@@ -501,6 +504,22 @@ def validate_rake_extensions(builder) # :nodoc:
501504 WARNING
502505 end
503506
507+ def validate_unique_links
508+ links = @specification . metadata . slice ( *METADATA_LINK_KEYS )
509+ grouped = links . group_by { |_key , uri | uri }
510+ grouped . each do |uri , copies |
511+ next unless copies . length > 1
512+ keys = copies . map ( &:first ) . join ( "\n " )
513+ warning <<~WARNING
514+ You have specified the uri:
515+ #{ uri }
516+ for all of the following keys:
517+ #{ keys }
518+ Only the first one will be shown on rubygems.org
519+ WARNING
520+ end
521+ end
522+
504523 def warning ( statement ) # :nodoc:
505524 @warnings += 1
506525
Original file line number Diff line number Diff line change @@ -3644,6 +3644,38 @@ def test_metadata_link_validation_fails
36443644 end
36453645 end
36463646
3647+ def test_metadata_link_validation_warns_for_duplicates
3648+ util_setup_validate
3649+
3650+ Dir . chdir @tempdir do
3651+ @m2 = quick_gem "m" , "2" do |s |
3652+ s . files = %w[ lib/code.rb ]
3653+ s . licenses = "BSD-2-Clause"
3654+ s . metadata = {
3655+ "source_code_uri" => "http://example.com" ,
3656+ "homepage_uri" => "http://example.com" ,
3657+ "changelog_uri" => "http://example.com/changelog" ,
3658+ }
3659+ end
3660+
3661+ use_ui @ui do
3662+ @m2 . validate
3663+ end
3664+
3665+ expected = <<~EXPECTED
3666+ #{ w } : You have specified the uri:
3667+ http://example.com
3668+ for all of the following keys:
3669+ homepage_uri
3670+ source_code_uri
3671+ Only the first one will be shown on rubygems.org
3672+ #{ w } : See https://guides.rubygems.org/specification-reference/ for help
3673+ EXPECTED
3674+
3675+ assert_equal expected , @ui . error , "warning"
3676+ end
3677+ end
3678+
36473679 def test_metadata_specs
36483680 @m1 = quick_gem "m" , "1" do |s |
36493681 s . files = %w[ lib/code.rb ]
You can’t perform that action at this time.
0 commit comments