summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/license/management/repository.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb
index 0c428dd..fdff30d 100644
--- a/lib/license/management/repository.rb
+++ b/lib/license/management/repository.rb
@@ -25,6 +25,8 @@ module License
attr_reader :spdx_data, :compatibility_data
def spdx_data_for(id)
+ return if blank?(id)
+
data = spdx_data[id]
if data
{
@@ -40,7 +42,7 @@ module License
def id_for(license)
ids = compatibility_data['ids']
- ids[license.send(:short_name)] || ids[license.url]
+ ids[license.send(:short_name)] || ids[license.url] || known_sources(license.url)
end
# When `license_finder` is unable to determine the license it will use the full
@@ -54,9 +56,10 @@ module License
def generate_item_for(license)
log_info("detected unknown license named `#{license.send(:short_name)}`")
+ name = take_first_line_from(license.name)
{
- 'id' => 'unknown',
- 'name' => take_first_line_from(license.name),
+ 'id' => name.downcase,
+ 'name' => name,
'url' => present?(license.url) ? license.url : ''
}
end
@@ -71,6 +74,17 @@ module License
memo
end
end
+
+ def known_sources(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)
+
+ uri.path.split('/')[-1]
+ rescue
+ nil
+ end
end
end
end