From beefce1444adafac484bb69b625de2b30e7e80d2 Mon Sep 17 00:00:00 2001 From: Drew Stevenson Date: Thu, 30 Nov 2023 22:35:33 -0600 Subject: [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 --- lib/rubygems/specification_policy.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index ca5fa5fb72..6655825287 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -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 -- cgit v1.2.3