licensed 2.12.2 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42da8bbc3e526abe154311e85c5dcb1ffaeba7a631e3b6eab6dbb976a94d9c4d
4
- data.tar.gz: b0884fb5ae8a8c332c8ea8684075a57e3efe86c6026656279eb2ffe0ae50105a
3
+ metadata.gz: a4477f07cae2650a7d8679a9042f73a7d14d8de019088be22d09f30e0f8af4c2
4
+ data.tar.gz: b4cbd8769c1f98b1a0729e5d603ff08c15d2d5c5e4e8e029cd3bce7f69f395c1
5
5
  SHA512:
6
- metadata.gz: e5d14b32dffb12a412090348429a116f9732bb6413bc35fb677dbf248e8af415ca531d7980bafeaa5a81ed2f083e798821cd21be7fd8eed1037a6659f24d4693
7
- data.tar.gz: 411785733af02c33cc0b239980558f79389b8bfdc144bf862530fde111dc3ad0c8fd64040b9fdecba022ae93158287b0f45e26a10719567dda3022024a60728b
6
+ metadata.gz: 83e7612e7a1fe2dbb77d48893c68db036630a45cdbc37f38f6630be0380231d9ac7fc0d37298d3a8a349d4bd43eb1dad64b7ec26a4b8d795806fb682091d94b7
7
+ data.tar.gz: 26e4fed8cede2d4de43fc511a85a82507dcc0cbcc9a66537d39a189d533a7cfbb22fdf2be5ad242ae72f4943fde6676c23b0bdcdf906beeecef813369177c158
@@ -116,7 +116,7 @@ jobs:
116
116
  runs-on: ubuntu-latest
117
117
  strategy:
118
118
  matrix:
119
- ruby: [ 2.4.x, 2.5.x, 2.6.x ]
119
+ ruby: [ 2.4.x, 2.5.x, 2.6.x, 2.7.x ]
120
120
  steps:
121
121
  - uses: actions/checkout@v2
122
122
  - name: Set up Ruby
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## 2.13.0
10
+ 2020-09-23
11
+
12
+ ### Added
13
+ - `status` command results can be output in YAML and JSON formats (:tada: @julianvilas https://github.com/github/licensed/pull/303)
14
+
15
+ ### Fixed
16
+ - `licensed` no longer crashes when parsing invalid YAML from cached records (https://github.com/github/licensed/pull/306)
17
+ - NPM source will no longer crash when invalid JSON is returned from npm CLI calls (https://github.com/github/licensed/pull/300)
18
+ - Bundler source is fixed to work properly with `gems.rb` lockfiles (https://github.com/github/licensed/pull/299)
19
+
9
20
  ## 2.12.2
10
21
  2020-07-07
11
22
 
@@ -17,7 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
17
28
  2020-06-30
18
29
 
19
30
  ### Fixed
20
- - `licensed` no longer exits an error code when using the `--sources` CLI argument(https://github.com/github/licensed/pull/290)
31
+ - `licensed` no longer exits an error code when using the `--sources` CLI argument (https://github.com/github/licensed/pull/290)
21
32
 
22
33
  ## 2.12.0
23
34
  2020-06-19
@@ -340,4 +351,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
340
351
 
341
352
  Initial release :tada:
342
353
 
343
- [Unreleased]: https://github.com/github/licensed/compare/2.12.2...HEAD
354
+ [Unreleased]: https://github.com/github/licensed/compare/2.13.0...HEAD
@@ -18,12 +18,14 @@ module Licensed
18
18
  end
19
19
 
20
20
  desc "status", "Check status of dependencies' cached licenses"
21
+ method_option :format, enum: ["yaml", "json"],
22
+ desc: "Output format"
21
23
  method_option :config, aliases: "-c", type: :string,
22
24
  desc: "Path to licensed configuration file"
23
25
  method_option :sources, aliases: "-s", type: :array,
24
26
  desc: "Individual source(s) to evaluate. Must also be enabled via configuration."
25
27
  def status
26
- run Licensed::Commands::Status.new(config: config), sources: options[:sources]
28
+ run Licensed::Commands::Status.new(config: config), sources: options[:sources], reporter: options[:format]
27
29
  end
28
30
 
29
31
  desc "list", "List dependencies"
@@ -57,7 +59,7 @@ module Licensed
57
59
  method_option :config, aliases: "-c", type: :string,
58
60
  desc: "Path to licensed configuration file"
59
61
  def env
60
- run Licensed::Commands::Environment.new(config: config), format: options[:format]
62
+ run Licensed::Commands::Environment.new(config: config), reporter: options[:format]
61
63
  end
62
64
 
63
65
  desc "migrate", "Migrate from a previous version of licensed"
@@ -2,12 +2,12 @@
2
2
  module Licensed
3
3
  module Commands
4
4
  class Cache < Command
5
- # Create a reporter to use during a command run
5
+ # Returns the default reporter to use during the command run
6
6
  #
7
7
  # options - The options the command was run with
8
8
  #
9
- # Raises a Licensed::Reporters::CacheReporter
10
- def create_reporter(options)
9
+ # Returns a Licensed::Reporters::CacheReporter
10
+ def default_reporter(options)
11
11
  Licensed::Reporters::CacheReporter.new
12
12
  end
13
13
 
@@ -37,13 +37,29 @@ module Licensed
37
37
  result
38
38
  end
39
39
 
40
- # Create a reporter to use during a command run
40
+ # Creates a reporter to use during a command run
41
41
  #
42
42
  # options - The options the command was run with
43
43
  #
44
- # Raises an error
44
+ # Returns the reporter to use during the command run
45
45
  def create_reporter(options)
46
- raise "`create_reporter` must be implemented by commands"
46
+ return options[:reporter] if options[:reporter].is_a?(Licensed::Reporters::Reporter)
47
+
48
+ if options[:reporter].is_a?(String)
49
+ klass = "#{options[:reporter].capitalize}Reporter"
50
+ return Licensed::Reporters.const_get(klass).new if Licensed::Reporters.const_defined?(klass)
51
+ end
52
+
53
+ default_reporter(options)
54
+ end
55
+
56
+ # Returns the default reporter to use during the command run
57
+ #
58
+ # options - The options the command was run with
59
+ #
60
+ # Raises an error
61
+ def default_reporter(options)
62
+ raise "`default_reporter` must be implemented by commands"
47
63
  end
48
64
 
49
65
  protected
@@ -125,7 +141,7 @@ module Licensed
125
141
  end
126
142
 
127
143
  evaluate_dependency(app, source, dependency, report)
128
- rescue Licensed::Shell::Error => err
144
+ rescue Licensed::DependencyRecord::Error, Licensed::Shell::Error => err
129
145
  report.errors << err.message
130
146
  false
131
147
  end
@@ -35,13 +35,13 @@ module Licensed
35
35
  end
36
36
  end
37
37
 
38
- def create_reporter(options)
39
- case options[:format]
40
- when "json"
41
- Licensed::Reporters::JsonReporter.new
42
- else
43
- Licensed::Reporters::YamlReporter.new
44
- end
38
+ # Returns the default reporter to use during the command run
39
+ #
40
+ # options - The options the command was run with
41
+ #
42
+ # Returns a Licensed::Reporters::StatusReporter
43
+ def default_reporter(options)
44
+ Licensed::Reporters::YamlReporter.new
45
45
  end
46
46
 
47
47
  protected
@@ -2,12 +2,12 @@
2
2
  module Licensed
3
3
  module Commands
4
4
  class List < Command
5
- # Create a reporter to use during a command run
5
+ # Returns the default reporter to use during the command run
6
6
  #
7
7
  # options - The options the command was run with
8
8
  #
9
9
  # Returns a Licensed::Reporters::ListReporter
10
- def create_reporter(options)
10
+ def default_reporter(options)
11
11
  Licensed::Reporters::ListReporter.new
12
12
  end
13
13
 
@@ -2,12 +2,12 @@
2
2
  module Licensed
3
3
  module Commands
4
4
  class Notices < Command
5
- # Create a reporter to use during a command run
5
+ # Returns the default reporter to use during the command run
6
6
  #
7
7
  # options - The options the command was run with
8
8
  #
9
- # Raises a Licensed::Reporters::CacheReporter
10
- def create_reporter(options)
9
+ # Returns a Licensed::Reporters::CacheReporter
10
+ def default_reporter(options)
11
11
  Licensed::Reporters::NoticesReporter.new
12
12
  end
13
13
 
@@ -4,12 +4,12 @@ require "yaml"
4
4
  module Licensed
5
5
  module Commands
6
6
  class Status < Command
7
- # Create a reporter to use during a command run
7
+ # Returns the default reporter to use during the command run
8
8
  #
9
9
  # options - The options the command was run with
10
10
  #
11
11
  # Returns a Licensed::Reporters::StatusReporter
12
- def create_reporter(options)
12
+ def default_reporter(options)
13
13
  Licensed::Reporters::StatusReporter.new
14
14
  end
15
15
 
@@ -5,6 +5,8 @@ require "licensee"
5
5
 
6
6
  module Licensed
7
7
  class DependencyRecord
8
+ class Error < StandardError; end
9
+
8
10
  class License
9
11
  attr_reader :text, :sources
10
12
  def initialize(content)
@@ -46,6 +48,8 @@ module Licensed
46
48
  notices: data.delete("notices"),
47
49
  metadata: data
48
50
  )
51
+ rescue Psych::SyntaxError => e
52
+ raise Licensed::DependencyRecord::Error.new(e.message)
49
53
  end
50
54
 
51
55
  def_delegators :@metadata, :[], :[]=
@@ -74,7 +74,7 @@ module Licensed
74
74
  end
75
75
  end
76
76
 
77
- GEMFILES = %w{Gemfile gems.rb}.freeze
77
+ GEMFILES = { "Gemfile" => "Gemfile.lock", "gems.rb" => "gems.locked" }
78
78
  DEFAULT_WITHOUT_GROUPS = %i{development test}
79
79
 
80
80
  def enabled?
@@ -272,14 +272,15 @@ module Licensed
272
272
 
273
273
  # Returns the path to the Bundler Gemfile
274
274
  def gemfile_path
275
- @gemfile_path ||= GEMFILES.map { |g| config.pwd.join g }
275
+ @gemfile_path ||= GEMFILES.keys
276
+ .map { |g| config.pwd.join g }
276
277
  .find { |f| f.exist? }
277
278
  end
278
279
 
279
280
  # Returns the path to the Bundler Gemfile.lock
280
281
  def lockfile_path
281
282
  return unless gemfile_path
282
- @lockfile_path ||= gemfile_path.dirname.join("#{gemfile_path.basename}.lock")
283
+ @lockfile_path ||= gemfile_path.dirname.join(GEMFILES[gemfile_path.basename.to_s])
283
284
  end
284
285
 
285
286
  # Returns the configured bundler executable to use, or "bundle" by default.
@@ -30,7 +30,7 @@ module Licensed
30
30
  end
31
31
 
32
32
  def packages
33
- root_dependencies = JSON.parse(package_metadata_command)["dependencies"]
33
+ root_dependencies = package_metadata["dependencies"]
34
34
  recursive_dependencies(root_dependencies).each_with_object({}) do |(name, results), hsh|
35
35
  results.uniq! { |package| package["version"] }
36
36
  if results.size == 1
@@ -56,6 +56,18 @@ module Licensed
56
56
  result
57
57
  end
58
58
 
59
+ # Returns parsed package metadata returned from `npm list`
60
+ def package_metadata
61
+ return @package_metadata if defined?(@package_metadata)
62
+
63
+ @package_metadata = begin
64
+ JSON.parse(package_metadata_command)
65
+ rescue JSON::ParserError => e
66
+ raise Licensed::Sources::Source::Error,
67
+ "Licensed was unable to parse the output from 'npm list'. Please run 'npm list --json --long' and check for errors. Error: #{e.message}"
68
+ end
69
+ end
70
+
59
71
  # Returns the output from running `npm list` to get package metadata
60
72
  def package_metadata_command
61
73
  args = %w(--json --long)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Licensed
3
- VERSION = "2.12.2".freeze
3
+ VERSION = "2.13.0".freeze
4
4
 
5
5
  def self.previous_major_versions
6
6
  major_version = Gem::Version.new(Licensed::VERSION).segments.first
@@ -38,5 +38,4 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "rubocop", "~> 0.49", "< 0.67"
39
39
  spec.add_development_dependency "rubocop-github", "~> 0.6"
40
40
  spec.add_development_dependency "byebug", "~> 10.0.0"
41
- spec.add_development_dependency "spy", "~> 1.0.0"
42
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: licensed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.2
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: licensee
@@ -218,20 +218,6 @@ dependencies:
218
218
  - - "~>"
219
219
  - !ruby/object:Gem::Version
220
220
  version: 10.0.0
221
- - !ruby/object:Gem::Dependency
222
- name: spy
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - "~>"
226
- - !ruby/object:Gem::Version
227
- version: 1.0.0
228
- type: :development
229
- prerelease: false
230
- version_requirements: !ruby/object:Gem::Requirement
231
- requirements:
232
- - - "~>"
233
- - !ruby/object:Gem::Version
234
- version: 1.0.0
235
221
  description: Licensed automates extracting and validating the licenses of dependencies.
236
222
  email:
237
223
  - opensource+licensed@github.com