licensee 9.16.0 → 9.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/bin/licensee +4 -2
  3. data/lib/licensee/commands/detect.rb +1 -0
  4. data/lib/licensee/commands/license_path.rb +8 -8
  5. data/lib/licensee/content_helper.rb +4 -4
  6. data/lib/licensee/license.rb +2 -2
  7. data/lib/licensee/license_field.rb +2 -2
  8. data/lib/licensee/license_meta.rb +2 -2
  9. data/lib/licensee/matchers/cabal.rb +1 -1
  10. data/lib/licensee/matchers/cargo.rb +1 -1
  11. data/lib/licensee/matchers/copyright.rb +3 -3
  12. data/lib/licensee/matchers/cran.rb +3 -3
  13. data/lib/licensee/matchers/dist_zilla.rb +1 -1
  14. data/lib/licensee/matchers/gemspec.rb +5 -5
  15. data/lib/licensee/matchers/npm_bower.rb +1 -1
  16. data/lib/licensee/matchers/nuget.rb +6 -6
  17. data/lib/licensee/matchers/spdx.rb +1 -1
  18. data/lib/licensee/project_files/license_file.rb +9 -9
  19. data/lib/licensee/project_files/readme_file.rb +3 -3
  20. data/lib/licensee/projects/fs_project.rb +2 -2
  21. data/lib/licensee/projects/git_project.rb +2 -2
  22. data/lib/licensee/projects/github_project.rb +15 -6
  23. data/lib/licensee/projects/project.rb +3 -3
  24. data/lib/licensee/rule.rb +1 -1
  25. data/lib/licensee/version.rb +1 -1
  26. data/spec/fixtures/detect.json +1 -1
  27. data/spec/fixtures/license-hashes.json +2 -0
  28. data/spec/fixtures/webmock/licensee_alternate_ref.json +26 -0
  29. data/spec/licensee/commands/license_path_spec.rb +3 -2
  30. data/spec/licensee/content_helper_spec.rb +1 -1
  31. data/spec/licensee/license_meta_spec.rb +2 -2
  32. data/spec/licensee/license_spec.rb +2 -2
  33. data/spec/licensee/matchers/cran_matcher_spec.rb +0 -2
  34. data/spec/licensee/projects/{github_project_spec.rb → git_hub_project_spec.rb} +36 -4
  35. data/spec/licensee_spec.rb +1 -1
  36. data/spec/spec_helper.rb +1 -1
  37. data/vendor/choosealicense.com/_licenses/blueoak-1.0.0.txt +84 -0
  38. data/vendor/choosealicense.com/_licenses/bsd-2-clause-patent.txt +76 -0
  39. data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +1 -1
  40. data/vendor/choosealicense.com/_licenses/epl-1.0.txt +1 -1
  41. data/vendor/choosealicense.com/_licenses/epl-2.0.txt +3 -3
  42. data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +1 -1
  43. data/vendor/choosealicense.com/_licenses/odbl-1.0.txt +1 -1
  44. data/vendor/choosealicense.com/_licenses/upl-1.0.txt +4 -4
  45. data/vendor/license-list-XML/src/0BSD.xml +2 -1
  46. data/vendor/license-list-XML/src/AGPL-3.0.xml +2 -2
  47. data/vendor/license-list-XML/src/Apache-2.0.xml +2 -2
  48. data/vendor/license-list-XML/src/BSD-2-Clause-Patent.xml +91 -0
  49. data/vendor/license-list-XML/src/BSD-2-Clause.xml +2 -2
  50. data/vendor/license-list-XML/src/BSD-3-Clause-Clear.xml +1 -1
  51. data/vendor/license-list-XML/src/BSD-3-Clause.xml +9 -9
  52. data/vendor/license-list-XML/src/BlueOak-1.0.0.xml +31 -0
  53. data/vendor/license-list-XML/src/CC-BY-4.0.xml +12 -12
  54. data/vendor/license-list-XML/src/CC-BY-SA-4.0.xml +12 -12
  55. data/vendor/license-list-XML/src/CECILL-2.1.xml +1 -1
  56. data/vendor/license-list-XML/src/EPL-2.0.xml +1 -1
  57. data/vendor/license-list-XML/src/EUPL-1.2.xml +1 -1
  58. data/vendor/license-list-XML/src/GFDL-1.3.xml +1 -1
  59. data/vendor/license-list-XML/src/GPL-2.0.xml +5 -5
  60. data/vendor/license-list-XML/src/GPL-3.0.xml +1 -1
  61. data/vendor/license-list-XML/src/LGPL-2.1.xml +1 -1
  62. data/vendor/license-list-XML/src/LGPL-3.0.xml +1 -1
  63. data/vendor/license-list-XML/src/MIT.xml +2 -2
  64. data/vendor/license-list-XML/src/MulanPSL-2.0.xml +1 -1
  65. data/vendor/license-list-XML/src/UPL-1.0.xml +1 -1
  66. data/vendor/license-list-XML/src/Unlicense.xml +1 -1
  67. data/vendor/license-list-XML/src/Vim.xml +1 -1
  68. data/vendor/license-list-XML/src/WTFPL.xml +1 -1
  69. metadata +26 -16
  70. data/licensee.gemspec +0 -47
  71. /data/spec/licensee/project_files/{package_info_spec.rb → package_manager_file_spec.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a971ca02733f55d37c599851a056742f8c40d758744c252c778c245082db6b3c
4
- data.tar.gz: 5cd7c9da75de50b045a68510cb9ab9442029f4a5ce3ae7011438686161de1c03
3
+ metadata.gz: fcfd6caf41091c1b39ac120a61729786b14cce5e814f6d5fdcb46705c53ab0b6
4
+ data.tar.gz: 8d8d4d6b4beb0062ab28ee47171cc30009c2713aeddccd789c493b82b98db2fd
5
5
  SHA512:
6
- metadata.gz: be105dd2fee2e5e81d340be6692deb0119d3fa478732f0802b70a36f1e93994922c2c3b2567dee6518b53be75af4f7bc520addd472c791786337332bed386cd9
7
- data.tar.gz: f53af3d80fd536f46767ae2316df97411b4aa4483dd3bf80f5bb3ee3ba39f5334e4c9b5276338b9d00f378347ba503ea8f804102573a32b73699ac98a1c5ec8f
6
+ metadata.gz: 57286ce86923c9dd5aeb47f3f825667040034459ae43744a50c5085a629f02b4ffad76a6ce6a28d86c5aad25d4776fceec13e4f9a0bde8aa94505b83a62868e2
7
+ data.tar.gz: 3f452acd71edba99d0043352900e3e88cd9009a6cb64dfacd184b73ffcfa408b4ec0166a5fc1f064593afd166e7ad064de3bd54c4803ded33419e09ec547fea0
data/bin/licensee CHANGED
@@ -28,7 +28,9 @@ class LicenseeCLI < Thor
28
28
 
29
29
  def project
30
30
  @project ||= Licensee.project(path,
31
- detect_packages: options[:packages], detect_readme: options[:readme])
31
+ detect_packages: options[:packages],
32
+ detect_readme: options[:readme],
33
+ ref: options[:ref])
32
34
  end
33
35
 
34
36
  def remote?
@@ -37,6 +39,6 @@ class LicenseeCLI < Thor
37
39
  end
38
40
 
39
41
  commands_dir = File.expand_path '../lib/licensee/commands/', __dir__
40
- Dir["#{commands_dir}/*.rb"].sort.each { |c| require(c) }
42
+ Dir["#{commands_dir}/*.rb"].each { |c| require(c) }
41
43
 
42
44
  LicenseeCLI.start(ARGV)
@@ -13,6 +13,7 @@ class LicenseeCLI < Thor
13
13
  option :confidence, type: :numeric, default: Licensee.confidence_threshold, desc: 'Confidence threshold'
14
14
  option :license, type: :string, desc: 'The SPDX ID or key of the license to compare (implies --diff)'
15
15
  option :diff, type: :boolean, desc: 'Compare the license to the closest match'
16
+ option :ref, type: :string, desc: 'The name of the commit/branch/tag to search (github.com only)'
16
17
  def detect(_path = nil)
17
18
  Licensee.confidence_threshold = options[:confidence]
18
19
 
@@ -2,15 +2,15 @@
2
2
 
3
3
  class LicenseeCLI < Thor
4
4
  desc 'license-path [PATH]', "Returns the path to the given project's license file"
5
- def license_path(_path)
6
- if project.license_file
7
- if remote?
8
- say project.license_file.path
9
- else
10
- say File.expand_path project.license_file.path
11
- end
5
+ def license_path(path)
6
+ project = Licensee.project(path)
7
+
8
+ exit 1 unless project.license_file
9
+
10
+ if remote?
11
+ say project.license_file.path
12
12
  else
13
- exit 1
13
+ say File.expand_path(project.license_file.path, path)
14
14
  end
15
15
  end
16
16
  end
@@ -6,8 +6,8 @@ require 'digest'
6
6
  module Licensee
7
7
  module ContentHelper
8
8
  DIGEST = Digest::SHA1
9
- START_REGEX = /\A\s*/.freeze
10
- END_OF_TERMS_REGEX = /^[\s#*_]*end of (the )?terms and conditions[\s#*_]*$/i.freeze
9
+ START_REGEX = /\A\s*/
10
+ END_OF_TERMS_REGEX = /^[\s#*_]*end of (the )?terms and conditions[\s#*_]*$/i
11
11
  REGEXES = {
12
12
  bom: /#{START_REGEX}\xEF\xBB\xBF/,
13
13
  hrs: /^\s*[=\-*]{3,}\s*$/,
@@ -304,8 +304,8 @@ module Licensee
304
304
 
305
305
  if operation
306
306
  @_content = _content.gsub operation[:from], operation[:to]
307
- elsif respond_to?("normalize_#{from_or_key}", true)
308
- send("normalize_#{from_or_key}")
307
+ elsif respond_to?(:"normalize_#{from_or_key}", true)
308
+ send(:"normalize_#{from_or_key}")
309
309
  else
310
310
  raise ArgumentError, "#{from_or_key} is an invalid normalization"
311
311
  end
@@ -98,8 +98,8 @@ module Licensee
98
98
  pseudo: true
99
99
  }.freeze
100
100
 
101
- SOURCE_PREFIX = %r{https?://(?:www\.)?}i.freeze
102
- SOURCE_SUFFIX = %r{(?:\.html?|\.txt|/)(?:\?[^\s]*)?}i.freeze
101
+ SOURCE_PREFIX = %r{https?://(?:www\.)?}i
102
+ SOURCE_SUFFIX = %r{(?:\.html?|\.txt|/)(?:\?[^\s]*)?}i
103
103
 
104
104
  HASH_METHODS = %i[
105
105
  key spdx_id meta url rules fields other? gpl? lgpl? cc?
@@ -22,7 +22,7 @@ module Licensee
22
22
  @all ||= begin
23
23
  path = '../../vendor/choosealicense.com/_data/fields.yml'
24
24
  path = File.expand_path path, __dir__
25
- fields = YAML.safe_load File.read(path)
25
+ fields = YAML.safe_load_file(path)
26
26
  fields.map { |field| LicenseField.from_hash(field) }
27
27
  end
28
28
  end
@@ -47,7 +47,7 @@ module Licensee
47
47
  end
48
48
 
49
49
  alias key name
50
- FIELD_REGEX = /\[(#{Regexp.union(LicenseField.keys)})\]/.freeze
50
+ FIELD_REGEX = /\[(#{Regexp.union(LicenseField.keys)})\]/
51
51
 
52
52
  # The human-readable field name
53
53
  def label
@@ -43,12 +43,12 @@ module Licensee
43
43
 
44
44
  # Array of symbolized helper methods to expose on the License class
45
45
  def helper_methods
46
- members - PREDICATE_FIELDS + PREDICATE_FIELDS.map { |f| "#{f}?".to_sym }
46
+ members - PREDICATE_FIELDS + PREDICATE_FIELDS.map { |f| :"#{f}?" }
47
47
  end
48
48
  end
49
49
 
50
50
  PREDICATE_FIELDS.each do |field|
51
- alias_method "#{field}?".to_sym, field
51
+ alias_method :"#{field}?", field
52
52
  end
53
53
 
54
54
  # Backward compatibalize `#["spdx-id"]` calls to avoid a breaking change
@@ -5,7 +5,7 @@ module Licensee
5
5
  class Cabal < Licensee::Matchers::Package
6
6
  # While we could parse the cabal file, prefer
7
7
  # a lenient regex for speed and security. Moar parsing moar problems.
8
- LICENSE_REGEX = /^\s*license\s*:\s*([a-z\-0-9.]+)\s*$/ix.freeze
8
+ LICENSE_REGEX = /^\s*license\s*:\s*([a-z\-0-9.]+)\s*$/ix
9
9
  LICENSE_CONVERSIONS = {
10
10
  'GPL-2' => 'GPL-2.0',
11
11
  'GPL-3' => 'GPL-3.0',
@@ -5,7 +5,7 @@ module Licensee
5
5
  class Cargo < Licensee::Matchers::Package
6
6
  LICENSE_REGEX = %r{
7
7
  ^\s*['"]?license['"]?\s*=\s*['"]([a-z\-0-9. +()/]+)['"]\s*
8
- }ix.freeze
8
+ }ix
9
9
 
10
10
  private
11
11
 
@@ -6,9 +6,9 @@ module Licensee
6
6
  attr_reader :file
7
7
 
8
8
  COPYRIGHT_SYMBOLS = Regexp.union([/copyright/i, /\(c\)/i, "\u00A9", "\xC2\xA9"])
9
- MAIN_LINE_REGEX = /[_*\-\s]*#{COPYRIGHT_SYMBOLS}.*$/i.freeze
10
- OPTIONAL_LINE_REGEX = /[_*\-\s]*with Reserved Font Name.*$/i.freeze
11
- REGEX = /#{ContentHelper::START_REGEX}(#{MAIN_LINE_REGEX}#{OPTIONAL_LINE_REGEX}*)+$/i.freeze
9
+ MAIN_LINE_REGEX = /[_*\-\s]*#{COPYRIGHT_SYMBOLS}.*$/i
10
+ OPTIONAL_LINE_REGEX = /[_*\-\s]*with Reserved Font Name.*$/i
11
+ REGEX = /#{ContentHelper::START_REGEX}(#{MAIN_LINE_REGEX}#{OPTIONAL_LINE_REGEX}*)+$/i
12
12
  def match
13
13
  # NOTE: must use content, and not content_normalized here
14
14
  Licensee::License.find('no-license') if /#{REGEX}+\z/io.match?(file.content.strip)
@@ -7,9 +7,9 @@ module Licensee
7
7
 
8
8
  # While we could parse the DESCRIPTION file, prefer
9
9
  # a lenient regex for speed and security. Moar parsing moar problems.
10
- LICENSE_FIELD_REGEX = /^license:\s*(.+)/i.freeze
11
- PLUS_FILE_LICENSE_REGEX = /\s*\+\s*file\s+LICENSE$/i.freeze
12
- GPL_VERSION_REGEX = /^GPL(?:-([23])|\s*\(\s*>=\s*([23])\s*\))$/i.freeze
10
+ LICENSE_FIELD_REGEX = /^license:\s*(.+)/i
11
+ PLUS_FILE_LICENSE_REGEX = /\s*\+\s*file\s+LICENSE$/i
12
+ GPL_VERSION_REGEX = /^GPL(?:-([23])|\s*\(\s*>=\s*([23])\s*\))$/i
13
13
 
14
14
  private
15
15
 
@@ -5,7 +5,7 @@ module Licensee
5
5
  class DistZilla < Licensee::Matchers::Package
6
6
  attr_reader :file
7
7
 
8
- LICENSE_REGEX = /^license\s*=\s*([a-z\-0-9._]+)/i.freeze
8
+ LICENSE_REGEX = /^license\s*=\s*([a-z\-0-9._]+)/i
9
9
 
10
10
  private
11
11
 
@@ -5,24 +5,24 @@ module Licensee
5
5
  class Gemspec < Licensee::Matchers::Package
6
6
  # a value is a string surrounded by any amount of whitespace
7
7
  # optionally ended with (non-captured) ".freeze"
8
- VALUE_REGEX = /\s*['"]([a-z\-0-9.]+)['"](?:\.freeze)?\s*/i.freeze
8
+ VALUE_REGEX = /\s*['"]([a-z\-0-9.]+)['"](?:\.freeze)?\s*/i
9
9
 
10
10
  # an array contains one or more values. all values, or array itself,
11
11
  # can be surrounded by any amount of whitespace. do not capture
12
12
  # non-value groups
13
- ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i.freeze
13
+ ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i
14
14
 
15
15
  DECLARATION_REGEX = /
16
16
  ^\s*[a-z0-9_]+\.([a-z0-9_]+)\s*=#{VALUE_REGEX}$
17
- /ix.freeze
17
+ /ix
18
18
 
19
19
  LICENSE_REGEX = /
20
20
  ^\s*[a-z0-9_]+\.license\s*=#{VALUE_REGEX}$
21
- /ix.freeze
21
+ /ix
22
22
 
23
23
  LICENSE_ARRAY_REGEX = /
24
24
  ^\s*[a-z0-9_]+\.licenses\s*=#{ARRAY_REGEX}$
25
- /ix.freeze
25
+ /ix
26
26
 
27
27
  private
28
28
 
@@ -7,7 +7,7 @@ module Licensee
7
7
  # a lenient regex for speed and security. Moar parsing moar problems.
8
8
  LICENSE_REGEX = /
9
9
  \s*["']license["']\s*:\s*['"]([a-z\-0-9.+ ()]+)['"],?\s*
10
- /ix.freeze
10
+ /ix
11
11
 
12
12
  private
13
13
 
@@ -7,14 +7,14 @@ module Licensee
7
7
  # Moar parsing moar problems.
8
8
  LICENSE_REGEX = %r{
9
9
  <license\s*type\s*=\s*["']expression["']\s*>([a-z\-0-9. +()]+)</license\s*>
10
- }ix.freeze
10
+ }ix
11
11
 
12
- LICENSE_URL_REGEX = %r{<licenseUrl>\s*(.*)\s*</licenseUrl>}i.freeze
12
+ LICENSE_URL_REGEX = %r{<licenseUrl>\s*(.*)\s*</licenseUrl>}i
13
13
 
14
- NUGET_REGEX = %r{https?://licenses.nuget.org/(.*)}i.freeze
15
- OPENSOURCE_REGEX = %r{https?://(?:www\.)?opensource.org/licenses/(.*)}i.freeze
16
- SPDX_REGEX = %r{https?://(?:www\.)?spdx.org/licenses/(.*?)(?:\.html|\.txt)?$}i.freeze
17
- APACHE_REGEX = %r{https?://(?:www\.)?apache.org/licenses/(.*?)(?:\.html|\.txt)?$}i.freeze
14
+ NUGET_REGEX = %r{https?://licenses.nuget.org/(.*)}i
15
+ OPENSOURCE_REGEX = %r{https?://(?:www\.)?opensource.org/licenses/(.*)}i
16
+ SPDX_REGEX = %r{https?://(?:www\.)?spdx.org/licenses/(.*?)(?:\.html|\.txt)?$}i
17
+ APACHE_REGEX = %r{https?://(?:www\.)?apache.org/licenses/(.*?)(?:\.html|\.txt)?$}i
18
18
 
19
19
  private
20
20
 
@@ -5,7 +5,7 @@ module Licensee
5
5
  class Spdx < Licensee::Matchers::Package
6
6
  # While we could parse the LICENSE.spdx file, prefer
7
7
  # a lenient regex for speed and security. Moar parsing moar problems.
8
- LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9. +()]+)\s*/i.freeze
8
+ LICENSE_REGEX = /PackageLicenseDeclared:\s*([a-z\-0-9. +()]+)\s*/i
9
9
 
10
10
  private
11
11
 
@@ -7,29 +7,29 @@ module Licensee
7
7
 
8
8
  # List of extensions to give preference to
9
9
  PREFERRED_EXT = %w[md markdown txt html].freeze
10
- PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z/.freeze
10
+ PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z/
11
11
 
12
12
  # Regex to match any extension except .spdx or .header
13
- LICENSE_EXT_REGEX = %r{\.(?!spdx|header)[^./]+\z}i.freeze
13
+ LICENSE_EXT_REGEX = %r{\.(?!spdx|header)[^./]+\z}i
14
14
 
15
15
  # Regex to match any extension except a few unlikely as license
16
16
  # texts with complex filenames
17
- OTHER_EXT_REGEX = %r{\.(?!xml|go|gemspec)[^./]+\z}i.freeze
17
+ OTHER_EXT_REGEX = %r{\.(?!xml|go|gemspec)[^./]+\z}i
18
18
 
19
19
  # Regex to match any extension
20
- ANY_EXT_REGEX = %r{\.[^./]+\z}i.freeze
20
+ ANY_EXT_REGEX = %r{\.[^./]+\z}i
21
21
 
22
22
  # Regex to match, LICENSE, LICENCE, unlicense, etc.
23
- LICENSE_REGEX = /(un)?licen[sc]e/i.freeze
23
+ LICENSE_REGEX = /(un)?licen[sc]e/i
24
24
 
25
25
  # Regex to match COPYING, COPYRIGHT, etc.
26
- COPYING_REGEX = /copy(ing|right)/i.freeze
26
+ COPYING_REGEX = /copy(ing|right)/i
27
27
 
28
28
  # Regex to match OFL.
29
- OFL_REGEX = /ofl/i.freeze
29
+ OFL_REGEX = /ofl/i
30
30
 
31
31
  # BSD + PATENTS patent file
32
- PATENTS_REGEX = /patents/i.freeze
32
+ PATENTS_REGEX = /patents/i
33
33
 
34
34
  # Hash of Regex => score with which to score potential license files
35
35
  FILENAME_REGEXES = {
@@ -55,7 +55,7 @@ module Licensee
55
55
  # detected as CC-BY or CC-BY-SA which are 98%+ similar
56
56
  CC_FALSE_POSITIVE_REGEX = /
57
57
  ^(creative\ commons\ )?Attribution-(NonCommercial|NoDerivatives)
58
- /xi.freeze
58
+ /xi
59
59
 
60
60
  def possible_matchers
61
61
  [Matchers::Copyright, Matchers::Exact, Matchers::Dice]
@@ -9,8 +9,8 @@ module Licensee
9
9
  /\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
10
10
  }.freeze
11
11
 
12
- TITLE_REGEX = /licen[sc]e:?/i.freeze
13
- UNDERLINE_REGEX = /\n[-=]+/m.freeze
12
+ TITLE_REGEX = /licen[sc]e:?/i
13
+ UNDERLINE_REGEX = /\n[-=]+/m
14
14
  CONTENT_REGEX = /^
15
15
  (?: # Header lookbehind
16
16
  [\#=]+\s#{TITLE_REGEX}\s*[\#=]* # Start of hashes or rdoc header
@@ -27,7 +27,7 @@ module Licensee
27
27
  |
28
28
  \z # End of file
29
29
  )
30
- /mix.freeze
30
+ /mix
31
31
 
32
32
  def possible_matchers
33
33
  super.push(Matchers::Reference)
@@ -34,11 +34,11 @@ module Licensee
34
34
  def files
35
35
  @files ||= search_directories.flat_map do |dir|
36
36
  relative_dir = Pathname.new(dir).relative_path_from(dir_path).to_s
37
- Dir.glob(::File.join(dir, @pattern).tr('\\', '/')).map do |file|
37
+ Dir.glob(::File.join(dir, @pattern).tr('\\', '/')).filter_map do |file|
38
38
  next unless ::File.file?(file)
39
39
 
40
40
  { name: ::File.basename(file), dir: relative_dir }
41
- end.compact
41
+ end
42
42
  end
43
43
  end
44
44
 
@@ -71,9 +71,9 @@ module Licensee
71
71
  end
72
72
 
73
73
  def files_from_tree(tree, dir = '.')
74
- tree.select { |e| e[:type] == :blob }.map do |entry|
74
+ tree.select { |e| e[:type] == :blob }.filter_map do |entry|
75
75
  entry.merge(dir: dir)
76
- end.compact
76
+ end
77
77
  end
78
78
  end
79
79
  end
@@ -12,22 +12,24 @@ autoload :Octokit, 'octokit'
12
12
  module Licensee
13
13
  module Projects
14
14
  class GitHubProject < Licensee::Projects::Project
15
+ attr_reader :ref, :repo
16
+
15
17
  # If there's any trailing data (e.g. `.git`) this pattern will ignore it:
16
18
  # we're going to use the API rather than clone the repo.
17
19
  GITHUB_REPO_PATTERN =
18
- %r{https://github.com/([^/]+/([^/]+(?=\.git)|[^/]+)).*}.freeze
20
+ %r{https://github.com/([^/]+/([^/]+(?=\.git)|[^/]+)).*}
19
21
 
20
22
  class RepoNotFound < StandardError; end
21
23
 
22
- def initialize(github_url, **args)
24
+ def initialize(github_url, ref: nil, **args)
23
25
  @repo = github_url[GITHUB_REPO_PATTERN, 1]
24
26
  raise ArgumentError, "Not a github URL: #{github_url}" unless @repo
25
27
 
28
+ @ref = ref
29
+
26
30
  super(**args)
27
31
  end
28
32
 
29
- attr_reader :repo
30
-
31
33
  private
32
34
 
33
35
  def files
@@ -40,14 +42,21 @@ module Licensee
40
42
  raise RepoNotFound, msg
41
43
  end
42
44
 
45
+ def query_params
46
+ return { ref: @ref } unless @ref.nil?
47
+
48
+ {}
49
+ end
50
+
43
51
  def load_file(file)
44
52
  client.contents(@repo, path: file[:path],
45
- accept: 'application/vnd.github.v3.raw').to_s
53
+ accept: 'application/vnd.github.v3.raw',
54
+ query: query_params).to_s
46
55
  end
47
56
 
48
57
  def dir_files(path = nil)
49
58
  path = path.gsub('./', '') if path
50
- files = client.contents(@repo, path: path)
59
+ files = client.contents(@repo, path: path, query: query_params)
51
60
  files = files.select { |data| data[:type] == 'file' }
52
61
  files.each { |data| data[:dir] = File.dirname(data[:path]) }
53
62
  files.map(&:to_h)
@@ -15,7 +15,7 @@ module Licensee
15
15
  include Licensee::HashHelper
16
16
  HASH_METHODS = %i[licenses matched_files].freeze
17
17
 
18
- def initialize(detect_packages: false, detect_readme: false)
18
+ def initialize(detect_packages: false, detect_readme: false, **)
19
19
  @detect_packages = detect_packages
20
20
  @detect_readme = detect_readme
21
21
  end
@@ -119,10 +119,10 @@ module Licensee
119
119
  # Given a block, passes each filename to that block, and expects a numeric
120
120
  # score in response. Returns a hash representing the top scoring file
121
121
  # or nil, if no file scored > 0
122
- def find_file(&block)
122
+ def find_file(...)
123
123
  return if files.empty? || files.nil?
124
124
 
125
- file = find_files(&block).first
125
+ file = find_files(...).first
126
126
  [load_file(file), file] if file
127
127
  end
128
128
 
data/lib/licensee/rule.rb CHANGED
@@ -43,7 +43,7 @@ module Licensee
43
43
  end
44
44
 
45
45
  def raw_rules
46
- YAML.safe_load File.read(Rule.file_path)
46
+ YAML.safe_load_file(Rule.file_path)
47
47
  end
48
48
 
49
49
  def groups
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Licensee
4
- VERSION = '9.16.0'
4
+ VERSION = '9.17.0'
5
5
  end
@@ -93,7 +93,7 @@
93
93
  },
94
94
  {
95
95
  "filename": "licensee.gemspec",
96
- "content": "# frozen_string_literal: true\n\nrequire File.expand_path('lib/licensee/version', __dir__)\n\nGem::Specification.new do |gem|\n gem.name = 'licensee'\n gem.version = Licensee::VERSION\n\n gem.summary = 'A Ruby Gem to detect open source project licenses'\n gem.description = <<-DESC\n Licensee automates the process of reading LICENSE files and\n compares their contents to known licenses using a fancy maths.\n DESC\n\n gem.authors = ['Ben Balter']\n gem.email = 'ben.balter@github.com'\n gem.homepage = 'https://github.com/benbalter/licensee'\n gem.license = 'MIT'\n gem.metadata['rubygems_mfa_required'] = 'true'\n\n gem.bindir = 'bin'\n gem.executables << 'licensee'\n\n gem.add_dependency('dotenv', '~> 2.0')\n gem.add_dependency('octokit', '>= 4.20', '< 7.0')\n gem.add_dependency('reverse_markdown', '>= 1', '< 3')\n gem.add_dependency('rugged', '>= 0.24', '<2.0')\n gem.add_dependency('thor', '>= 0.19', '< 2.0')\n\n gem.add_development_dependency('gem-release', '~> 2.0')\n gem.add_development_dependency('mustache', '>= 0.9', '< 2.0')\n gem.add_development_dependency('pry', '~> 0.9')\n gem.add_development_dependency('rspec', '~> 3.5')\n gem.add_development_dependency('rubocop', '~> 1.0')\n gem.add_development_dependency('rubocop-performance', '~> 1.5')\n gem.add_development_dependency('rubocop-rspec', '~> 2.0')\n gem.add_development_dependency('simplecov', '~> 0.16')\n gem.add_development_dependency('webmock', '~> 3.1')\n\n gem.required_ruby_version = '>= 2.6'\n\n # ensure the gem is built out of versioned files\n gem.files = Dir[\n '{bin,lib,man,test,vendor,spec}/**/*',\n 'README*', 'LICENSE*'\n ] & `git ls-files -z`.split(\"\\0\")\nend\n",
96
+ "content": "# frozen_string_literal: true\n\nrequire File.expand_path('lib/licensee/version', __dir__)\n\nGem::Specification.new do |gem|\n gem.name = 'licensee'\n gem.version = Licensee::VERSION\n\n gem.summary = 'A Ruby Gem to detect open source project licenses'\n gem.description = <<-DESC\n Licensee automates the process of reading LICENSE files and\n compares their contents to known licenses using a fancy maths.\n DESC\n\n gem.authors = ['Ben Balter']\n gem.email = 'ben.balter@github.com'\n gem.homepage = 'https://github.com/benbalter/licensee'\n gem.license = 'MIT'\n gem.metadata['rubygems_mfa_required'] = 'true'\n\n gem.bindir = 'bin'\n gem.executables << 'licensee'\n\n gem.add_dependency('dotenv', '>= 2', '< 4')\n gem.add_dependency('octokit', '>= 4.20', '< 9.0')\n gem.add_dependency('reverse_markdown', '>= 1', '< 3')\n gem.add_dependency('rugged', '>= 0.24', '<2.0')\n gem.add_dependency('thor', '>= 0.19', '< 2.0')\n\n gem.add_development_dependency('gem-release', '~> 2.0')\n gem.add_development_dependency('mustache', '>= 0.9', '< 2.0')\n gem.add_development_dependency('pry', '~> 0.9')\n gem.add_development_dependency('rspec', '~> 3.5')\n gem.add_development_dependency('rubocop', '~> 1.0')\n gem.add_development_dependency('rubocop-performance', '~> 1.5')\n gem.add_development_dependency('rubocop-rspec', '~> 2.0')\n gem.add_development_dependency('simplecov', '~> 0.16')\n gem.add_development_dependency('webmock', '~> 3.1')\n\n gem.required_ruby_version = '>= 3.0'\n\n # ensure the gem is built out of versioned files\n gem.files = Dir[\n '{bin,lib,man,test,vendor,spec}/**/*',\n 'README*', 'LICENSE*'\n ] & `git ls-files -z`.split(\"\\0\")\nend\n",
97
97
  "content_hash": null,
98
98
  "content_normalized": null,
99
99
  "matcher": {
@@ -4,7 +4,9 @@
4
4
  "agpl-3.0": "10486392ac9e730ec8f77bd1233edfc2d47dd23c",
5
5
  "apache-2.0": "bec905d850e7f5dc2e2db78a950d4a9db560a0b8",
6
6
  "artistic-2.0": "707698f0c53ab48d54b7fd2dc4a6f40533e8ebb3",
7
+ "blueoak-1.0.0": "4b1a6751488e0f5ac96e40f26cf4e3fc731b9daf",
7
8
  "bsd-2-clause": "a307ca750c21f262c95d2bce55e69c05e6c3dee9",
9
+ "bsd-2-clause-patent": "4098aa43dc82fbb6da400e2f5b1840d8b9fcea7f",
8
10
  "bsd-3-clause": "a961b19cc6921d510e29a13b0ba1a826fcffe41c",
9
11
  "bsd-3-clause-clear": "0fcdb12c4060ce8f406e17bc67787e50a9b36a61",
10
12
  "bsd-4-clause": "3b2917580b2b6f13efaaea37546b8b7a53716a30",
@@ -0,0 +1,26 @@
1
+ [
2
+ {
3
+ "name": "LICENSE",
4
+ "path": "LICENSE",
5
+ "sha": "sha1",
6
+ "size": 11357,
7
+ "url": "https://api.github.com/repos/benbalter/licensee/contents/LICENSE?ref=my-ref",
8
+ "html_url": "https://github.com/benbalter/licensee/blob/my-ref/LICENSE",
9
+ "git_url": "https://api.github.com/repos/benbalter/licensee/git/blobs/sha1",
10
+ "download_url": "https://raw.githubusercontent.com/benbalter/licensee/my-ref/LICENSE",
11
+ "type": "file",
12
+ "_links": {}
13
+ },
14
+ {
15
+ "name": "README.md",
16
+ "path": "README.md",
17
+ "sha": "sha2",
18
+ "size": 608,
19
+ "url": "https://api.github.com/repos/benbalter/licensee/contents/README.md?ref=my-ref",
20
+ "html_url": "https://github.com/benbalter/licensee/blob/my-ref/README.md",
21
+ "git_url": "https://api.github.com/repos/benbalter/licensee/git/blobs/sha2",
22
+ "download_url": "https://raw.githubusercontent.com/benbalter/licensee/my-ref/README.md",
23
+ "type": "file",
24
+ "_links": {}
25
+ }
26
+ ]
@@ -2,7 +2,8 @@
2
2
 
3
3
  RSpec.describe 'license-path command' do
4
4
  let(:command) { ['bundle', 'exec', 'bin/licensee', 'license-path'] }
5
- let(:arguments) { [project_root] }
5
+ let(:project_path) { fixture_path('mit_markdown') }
6
+ let(:arguments) { [project_path] }
6
7
  let(:output) do
7
8
  Dir.chdir project_root do
8
9
  Open3.capture3(*[command, arguments].flatten)
@@ -14,7 +15,7 @@ RSpec.describe 'license-path command' do
14
15
  let(:status) { output[2] }
15
16
 
16
17
  it 'returns the license path' do
17
- expect(stdout).to match(File.join(project_root, 'LICENSE.md'))
18
+ expect(stdout).to match(File.join(project_path, 'LICENSE.md'))
18
19
  end
19
20
 
20
21
  it 'Returns a zero exit code' do
@@ -111,7 +111,7 @@ RSpec.describe Licensee::ContentHelper do
111
111
  comment_markup: "/*\n* The MIT License\n* Foo\n*/",
112
112
  copyright_title: "Copyright 2019 Ben Balter\nMIT License\nFoo"
113
113
  }.each do |field, fixture|
114
- context "#strip_#{field}" do
114
+ describe "#strip_#{field}" do
115
115
  let(:content) { fixture }
116
116
 
117
117
  it "strips #{field}" do
@@ -28,11 +28,11 @@ RSpec.describe Licensee::LicenseMeta do
28
28
  described_class::PREDICATE_FIELDS.each do |field|
29
29
  context "the #{field}? method" do
30
30
  it 'responds' do
31
- expect(subject).to respond_to("#{field}?".to_sym)
31
+ expect(subject).to respond_to(:"#{field}?")
32
32
  end
33
33
 
34
34
  it 'is boolean' do
35
- expect(subject.send("#{field}?".to_sym)).to be(true).or be(false)
35
+ expect(subject.send(:"#{field}?")).to be(true).or be(false)
36
36
  end
37
37
  end
38
38
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Licensee::License do
4
- let(:license_count) { 47 }
5
- let(:hidden_license_count) { 34 }
4
+ let(:license_count) { 49 }
5
+ let(:hidden_license_count) { 36 }
6
6
  let(:featured_license_count) { 3 }
7
7
  let(:pseudo_license_count) { 2 }
8
8
  let(:non_featured_license_count) do
@@ -4,8 +4,6 @@ RSpec.describe Licensee::Matchers::Cran do
4
4
  subject { described_class.new(file) }
5
5
 
6
6
  let(:mit) { Licensee::License.find('mit') }
7
- let(:gpl2) { Licensee::License.find('gpl-2.0') }
8
- let(:gpl3) { Licensee::License.find('gpl-3.0') }
9
7
  let(:content) { "License: MIT + file LICENSE\nPackage: test" }
10
8
  let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'DESCRIPTION') }
11
9