diff options
| author | mo khan <mo.khan@gmail.com> | 2019-10-22 16:24:18 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-10-23 11:07:42 -0600 |
| commit | 9038552abe7c4b0ebca9795121f9d48564492b3c (patch) | |
| tree | 65c855c8803b8ccc13446ddf47f2cd444ffca5be /lib | |
| parent | ef5e5ec0b635d3968a6699b8d6711dd75f568b7d (diff) | |
Parse spdx id from known sources
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/license/management/repository.rb | 20 |
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 |
