From 4551c356c5975da9fc86c204f4aac4dee969feb9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 22 Oct 2019 17:10:03 -0600 Subject: Extract spdx id from known source urls --- lib/license/management/repository.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb index fdff30d..ed2519f 100644 --- a/lib/license/management/repository.rb +++ b/lib/license/management/repository.rb @@ -5,6 +5,11 @@ module License class Repository include Loggable include Verifiable + KNOWN_SOURCES = [ + 'licenses.nuget.org', + 'opensource.org', + 'www.opensource.org', + ].freeze def initialize( compatibility_path: License::Management.root.join('normalized-licenses.yml'), @@ -34,15 +39,15 @@ module License 'name' => data['name'], 'url' => data['seeAlso'][-1] } - else - log_info("Could not find license `#{id}` in SPDX") - nil end end def id_for(license) ids = compatibility_data['ids'] - ids[license.send(:short_name)] || ids[license.url] || known_sources(license.url) + ids[license.send(:short_name)] || + ids[license.url] || + known_sources(license.send(:short_name)) || + known_sources(license.url) end # When `license_finder` is unable to determine the license it will use the full @@ -55,7 +60,7 @@ module License end def generate_item_for(license) - log_info("detected unknown license named `#{license.send(:short_name)}`") + log_info("detected unknown license named `#{license.send(:short_name)}`:`#{license.url}`") name = take_first_line_from(license.name) { 'id' => name.downcase, @@ -76,13 +81,14 @@ module License end def known_sources(url) + return if blank?(url) return unless url =~ /\A#{::URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/ uri = URI.parse(url) - return unless ['opensource.org', 'licenses.nuget.org'].include?(uri.host) - + return unless KNOWN_SOURCES.include?(uri.host.downcase) uri.path.split('/')[-1] - rescue + rescue => error + log_info(error) nil end end -- cgit v1.2.3