diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-07 21:58:48 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-07 21:58:48 -0700 |
| commit | 3a6171fb149765a7c13c4bc365bf616c5aa9703d (patch) | |
| tree | 2f51de2e86f8122f2af4b414028e250cde084eba /lib | |
| parent | fd8c62ea5df2e9a983a9dc9c0741f88dc00b911d (diff) | |
Apply gitlab-styles
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/license/finder/ext.rb | 6 | ||||
| -rw-r--r-- | lib/license/management/repository.rb | 34 |
2 files changed, 22 insertions, 18 deletions
diff --git a/lib/license/finder/ext.rb b/lib/license/finder/ext.rb index 29db253..c431b6b 100644 --- a/lib/license/finder/ext.rb +++ b/lib/license/finder/ext.rb @@ -26,9 +26,13 @@ module LicenseFinder class Cmd def self.run(command) stdout, stderr, status = Open3.capture3(command) - puts stdout if ENV['CI_DEBUG_TRACE'] == 'true' + ::LicenseFinder::Core.default_logger.info(self.class, stdout) if ENV['CI_DEBUG_TRACE'] == 'true' [stdout, stderr, status] end end end + + class License + attr_reader :short_name, :pretty_name, :other_names + end end diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb index 9490af2..b13cec8 100644 --- a/lib/license/management/repository.rb +++ b/lib/license/management/repository.rb @@ -8,7 +8,7 @@ module License KNOWN_SOURCES = [ 'licenses.nuget.org', 'opensource.org', - 'www.opensource.org', + 'www.opensource.org' ].freeze def initialize( @@ -21,7 +21,7 @@ module License def item_for(license) spdx_data_for(id_for(license)) || - spdx_data_for(license.send(:short_name)) || + spdx_data_for(license.short_name) || generate_item_for(license) end @@ -33,20 +33,20 @@ module License return if blank?(id) data = spdx_data[id] - if data - { - 'id' => data['licenseId'], - 'name' => data['name'], - 'url' => data['seeAlso'][-1] - } - end + return unless data + + { + 'id' => data['licenseId'], + 'name' => data['name'], + 'url' => data['seeAlso'][-1] + } end def id_for(license) ids = compatibility_data['ids'] - ids[license.send(:short_name)] || + ids[license.short_name] || ids[license.url] || - known_sources(license.send(:short_name)) || + known_sources(license.short_name) || known_sources(license.url) end @@ -60,7 +60,7 @@ module License end def generate_item_for(license) - log_info("Detected unknown license `#{license.send(:short_name)}`. Contribute to https://gitlab.com/gitlab-org/security-products/license-management#contributing.") + log_info("Detected unknown license `#{license.short_name}`. Contribute to https://gitlab.com/gitlab-org/security-products/license-management#contributing.") name = take_first_line_from(license.name) { 'id' => name.downcase, @@ -74,21 +74,21 @@ module License json = JSON.parse(content) licenses = json['licenses'] - licenses.inject({}) do |memo, license| + licenses.each_with_object({}) do |license, memo| memo[license['licenseId']] = license - memo end end def known_sources(url) return if blank?(url) - return unless url =~ /\A#{::URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/ + return unless /\A#{::URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/.match?(url) uri = URI.parse(url) return unless KNOWN_SOURCES.include?(uri.host.downcase) + uri.path.split('/')[-1] - rescue => error - log_info(error) + rescue StandardError => e + log_info(e) nil end end |
