licensee 9.10.0 → 9.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/licensee +5 -4
- data/lib/licensee.rb +4 -2
- data/lib/licensee/commands/detect.rb +10 -5
- data/lib/licensee/commands/diff.rb +7 -8
- data/lib/licensee/commands/license_path.rb +2 -0
- data/lib/licensee/commands/version.rb +2 -0
- data/lib/licensee/content_helper.rb +234 -85
- data/lib/licensee/hash_helper.rb +7 -5
- data/lib/licensee/license.rb +32 -25
- data/lib/licensee/license_field.rb +4 -1
- data/lib/licensee/license_meta.rb +3 -0
- data/lib/licensee/license_rules.rb +2 -0
- data/lib/licensee/matchers.rb +2 -0
- data/lib/licensee/matchers/cabal.rb +16 -2
- data/lib/licensee/matchers/cargo.rb +3 -1
- data/lib/licensee/matchers/copyright.rb +6 -4
- data/lib/licensee/matchers/cran.rb +7 -3
- data/lib/licensee/matchers/dice.rb +6 -4
- data/lib/licensee/matchers/dist_zilla.rb +3 -1
- data/lib/licensee/matchers/exact.rb +3 -0
- data/lib/licensee/matchers/gemspec.rb +8 -5
- data/lib/licensee/matchers/matcher.rb +3 -1
- data/lib/licensee/matchers/npm_bower.rb +3 -1
- data/lib/licensee/matchers/package.rb +3 -0
- data/lib/licensee/matchers/reference.rb +3 -1
- data/lib/licensee/matchers/spdx.rb +3 -1
- data/lib/licensee/project_files.rb +2 -0
- data/lib/licensee/project_files/license_file.rb +13 -10
- data/lib/licensee/project_files/package_manager_file.rb +3 -0
- data/lib/licensee/project_files/project_file.rb +12 -4
- data/lib/licensee/project_files/readme_file.rb +5 -3
- data/lib/licensee/projects.rb +2 -0
- data/lib/licensee/projects/fs_project.rb +3 -0
- data/lib/licensee/projects/git_project.rb +19 -11
- data/lib/licensee/projects/github_project.rb +6 -1
- data/lib/licensee/projects/project.rb +16 -5
- data/lib/licensee/rule.rb +2 -0
- data/lib/licensee/version.rb +3 -1
- data/licensee.gemspec +47 -0
- data/spec/bin_spec.rb +3 -1
- data/spec/fixture_spec.rb +46 -0
- data/spec/fixtures/bsd-3-noendorseslash/LICENSE +30 -0
- data/spec/fixtures/cc0-cal2013/LICENSE +116 -0
- data/spec/fixtures/cc0-cc/LICENSE +121 -0
- data/spec/fixtures/detect.json +9 -7
- data/spec/fixtures/fixtures.yml +130 -0
- data/spec/fixtures/html/license.html +262 -0
- data/spec/fixtures/license-hashes.json +41 -0
- data/spec/fixtures/mit-optional/LICENSE.txt +21 -0
- data/spec/fixtures/multiple-arrs/LICENSE +30 -0
- data/spec/fixtures/unlicense-noinfo/LICENSE +22 -0
- data/spec/integration_spec.rb +68 -2
- data/spec/licensee/commands/detect_spec.rb +10 -6
- data/spec/licensee/commands/license_path_spec.rb +3 -1
- data/spec/licensee/commands/version_spec.rb +3 -1
- data/spec/licensee/content_helper_spec.rb +184 -67
- data/spec/licensee/hash_helper_spec.rb +3 -1
- data/spec/licensee/license_field_spec.rb +5 -3
- data/spec/licensee/license_meta_spec.rb +16 -12
- data/spec/licensee/license_rules_spec.rb +6 -2
- data/spec/licensee/license_spec.rb +62 -37
- data/spec/licensee/matchers/cabal_matcher_spec.rb +97 -2
- data/spec/licensee/matchers/cargo_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/copyright_matcher_spec.rb +7 -5
- data/spec/licensee/matchers/cran_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/dice_matcher_spec.rb +15 -12
- data/spec/licensee/matchers/dist_zilla_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/exact_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/gemspec_matcher_spec.rb +5 -2
- data/spec/licensee/matchers/matcher_spec.rb +6 -2
- data/spec/licensee/matchers/npm_bower_matcher_spec.rb +5 -3
- data/spec/licensee/matchers/package_matcher_spec.rb +6 -2
- data/spec/licensee/matchers/reference_matcher_spec.rb +4 -2
- data/spec/licensee/matchers/spdx_matcher_spec.rb +5 -2
- data/spec/licensee/project_files/license_file_spec.rb +20 -18
- data/spec/licensee/project_files/package_info_spec.rb +5 -1
- data/spec/licensee/project_files/project_file_spec.rb +8 -2
- data/spec/licensee/project_files/readme_file_spec.rb +4 -1
- data/spec/licensee/project_spec.rb +24 -17
- data/spec/licensee/projects/git_project_spec.rb +23 -0
- data/spec/licensee/projects/github_project_spec.rb +8 -5
- data/spec/licensee/rule_spec.rb +6 -3
- data/spec/licensee_spec.rb +12 -9
- data/spec/spec_helper.rb +28 -9
- data/spec/vendored_license_spec.rb +29 -10
- data/vendor/choosealicense.com/_data/meta.yml +0 -4
- data/vendor/choosealicense.com/_data/rules.yml +3 -0
- data/vendor/choosealicense.com/_licenses/0bsd.txt +39 -0
- data/vendor/choosealicense.com/_licenses/afl-3.0.txt +7 -6
- data/vendor/choosealicense.com/_licenses/agpl-3.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/apache-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/artistic-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/bsd-2-clause.txt +8 -6
- data/vendor/choosealicense.com/_licenses/bsd-3-clause-clear.txt +2 -2
- data/vendor/choosealicense.com/_licenses/bsd-3-clause.txt +12 -10
- data/vendor/choosealicense.com/_licenses/bsd-4-clause.txt +61 -0
- data/vendor/choosealicense.com/_licenses/bsl-1.0.txt +5 -2
- data/vendor/choosealicense.com/_licenses/cc-by-4.0.txt +3 -1
- data/vendor/choosealicense.com/_licenses/cc-by-sa-4.0.txt +3 -1
- data/vendor/choosealicense.com/_licenses/cc0-1.0.txt +113 -105
- data/vendor/choosealicense.com/_licenses/cecill-2.1.txt +579 -0
- data/vendor/choosealicense.com/_licenses/ecl-2.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/epl-1.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/epl-2.0.txt +3 -4
- data/vendor/choosealicense.com/_licenses/eupl-1.1.txt +0 -1
- data/vendor/choosealicense.com/_licenses/eupl-1.2.txt +0 -1
- data/vendor/choosealicense.com/_licenses/gpl-2.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/gpl-3.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/isc.txt +0 -1
- data/vendor/choosealicense.com/_licenses/lgpl-2.1.txt +0 -1
- data/vendor/choosealicense.com/_licenses/lgpl-3.0.txt +1 -3
- data/vendor/choosealicense.com/_licenses/lppl-1.3c.txt +1 -2
- data/vendor/choosealicense.com/_licenses/mit.txt +1 -2
- data/vendor/choosealicense.com/_licenses/mpl-2.0.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ms-pl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ms-rl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/ncsa.txt +21 -22
- data/vendor/choosealicense.com/_licenses/odbl-1.0.txt +573 -0
- data/vendor/choosealicense.com/_licenses/ofl-1.1.txt +4 -2
- data/vendor/choosealicense.com/_licenses/osl-3.0.txt +1 -2
- data/vendor/choosealicense.com/_licenses/postgresql.txt +4 -5
- data/vendor/choosealicense.com/_licenses/unlicense.txt +1 -2
- data/vendor/choosealicense.com/_licenses/upl-1.0.txt +4 -5
- data/vendor/choosealicense.com/_licenses/vim.txt +111 -0
- data/vendor/choosealicense.com/_licenses/wtfpl.txt +0 -1
- data/vendor/choosealicense.com/_licenses/zlib.txt +4 -2
- metadata +77 -19
@@ -1,26 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Licensee
|
2
4
|
module ProjectFiles
|
3
5
|
class LicenseFile < Licensee::ProjectFiles::ProjectFile
|
4
6
|
include Licensee::ContentHelper
|
5
7
|
|
6
8
|
# List of extensions to give preference to
|
7
|
-
PREFERRED_EXT = %w[md markdown txt].freeze
|
8
|
-
PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z
|
9
|
+
PREFERRED_EXT = %w[md markdown txt html].freeze
|
10
|
+
PREFERRED_EXT_REGEX = /\.#{Regexp.union(PREFERRED_EXT)}\z/.freeze
|
9
11
|
|
10
12
|
# Regex to match any extension except .spdx or .header
|
11
|
-
OTHER_EXT_REGEX = %r{\.(?!spdx|header|gemspec)[^./]+\z}i
|
13
|
+
OTHER_EXT_REGEX = %r{\.(?!spdx|header|gemspec)[^./]+\z}i.freeze
|
12
14
|
|
13
15
|
# Regex to match, LICENSE, LICENCE, unlicense, etc.
|
14
|
-
LICENSE_REGEX = /(un)?licen[sc]e/i
|
16
|
+
LICENSE_REGEX = /(un)?licen[sc]e/i.freeze
|
15
17
|
|
16
18
|
# Regex to match COPYING, COPYRIGHT, etc.
|
17
|
-
COPYING_REGEX = /copy(ing|right)/i
|
19
|
+
COPYING_REGEX = /copy(ing|right)/i.freeze
|
18
20
|
|
19
21
|
# Regex to match OFL.
|
20
|
-
OFL_REGEX = /ofl/i
|
22
|
+
OFL_REGEX = /ofl/i.freeze
|
21
23
|
|
22
24
|
# BSD + PATENTS patent file
|
23
|
-
PATENTS_REGEX = /patents/i
|
25
|
+
PATENTS_REGEX = /patents/i.freeze
|
24
26
|
|
25
27
|
# Hash of Regex => score with which to score potential license files
|
26
28
|
FILENAME_REGEXES = {
|
@@ -46,7 +48,7 @@ module Licensee
|
|
46
48
|
# detected as CC-BY or CC-BY-SA which are 98%+ similar
|
47
49
|
CC_FALSE_POSITIVE_REGEX = /
|
48
50
|
^(creative\ commons\ )?Attribution-(NonCommercial|NoDerivatives)
|
49
|
-
/xi
|
51
|
+
/xi.freeze
|
50
52
|
|
51
53
|
def possible_matchers
|
52
54
|
[Matchers::Copyright, Matchers::Exact, Matchers::Dice]
|
@@ -55,6 +57,7 @@ module Licensee
|
|
55
57
|
def attribution
|
56
58
|
@attribution ||= begin
|
57
59
|
return unless copyright? || license.content =~ /\[fullname\]/
|
60
|
+
|
58
61
|
matches = Matchers::Copyright::REGEX
|
59
62
|
.match(content_without_title_and_version)
|
60
63
|
matches[0] if matches
|
@@ -71,11 +74,11 @@ module Licensee
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def gpl?
|
74
|
-
license
|
77
|
+
license&.gpl?
|
75
78
|
end
|
76
79
|
|
77
80
|
def license
|
78
|
-
if matcher
|
81
|
+
if matcher&.match
|
79
82
|
matcher.match
|
80
83
|
else
|
81
84
|
License.find('other')
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Licensee
|
2
4
|
module ProjectFiles
|
3
5
|
class PackageManagerFile < Licensee::ProjectFiles::ProjectFile
|
@@ -32,6 +34,7 @@ module Licensee
|
|
32
34
|
|
33
35
|
def self.name_score(filename)
|
34
36
|
return 1.0 if ['.gemspec', '.cabal'].include?(File.extname(filename))
|
37
|
+
|
35
38
|
FILENAMES_SCORES[filename] || 0.0
|
36
39
|
end
|
37
40
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A project file is a file within a project that contains license information
|
2
4
|
# Currently extended by LicenseFile, PackageManagerFile, and ReadmeFile
|
3
5
|
#
|
@@ -13,6 +15,7 @@ module Licensee
|
|
13
15
|
include Licensee::HashHelper
|
14
16
|
HASH_METHODS = %i[
|
15
17
|
filename content content_hash content_normalized matcher matched_license
|
18
|
+
attribution
|
16
19
|
].freeze
|
17
20
|
|
18
21
|
ENCODING = Encoding::UTF_8
|
@@ -32,7 +35,7 @@ module Licensee
|
|
32
35
|
#
|
33
36
|
# Returns a new Licensee::ProjectFile
|
34
37
|
def initialize(content, metadata = {})
|
35
|
-
@content = content
|
38
|
+
@content = content.dup
|
36
39
|
@content.force_encoding(ENCODING)
|
37
40
|
unless @content.valid_encoding?
|
38
41
|
@content.encode!(ENCODING, ENCODING_OPTIONS)
|
@@ -70,17 +73,17 @@ module Licensee
|
|
70
73
|
|
71
74
|
# Returns the percent confident with the match
|
72
75
|
def confidence
|
73
|
-
matcher
|
76
|
+
matcher&.confidence
|
74
77
|
end
|
75
78
|
|
76
79
|
def license
|
77
|
-
matcher
|
80
|
+
matcher&.match
|
78
81
|
end
|
79
82
|
|
80
83
|
alias match license
|
81
84
|
|
82
85
|
def matched_license
|
83
|
-
license
|
86
|
+
license&.spdx_id
|
84
87
|
end
|
85
88
|
|
86
89
|
# Is this file a COPYRIGHT file with only a copyright statement?
|
@@ -88,6 +91,7 @@ module Licensee
|
|
88
91
|
def copyright?
|
89
92
|
return false unless is_a?(LicenseFile)
|
90
93
|
return false unless matcher.is_a?(Matchers::Copyright)
|
94
|
+
|
91
95
|
filename =~ /\Acopyright(?:#{LicenseFile::OTHER_EXT_REGEX})?\z/i
|
92
96
|
end
|
93
97
|
|
@@ -98,6 +102,10 @@ module Licensee
|
|
98
102
|
def content_normalized
|
99
103
|
nil
|
100
104
|
end
|
105
|
+
|
106
|
+
def attribution
|
107
|
+
nil
|
108
|
+
end
|
101
109
|
end
|
102
110
|
end
|
103
111
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Licensee
|
2
4
|
module ProjectFiles
|
3
5
|
class ReadmeFile < Licensee::ProjectFiles::LicenseFile
|
@@ -7,8 +9,8 @@ module Licensee
|
|
7
9
|
/\AREADME\.(#{Regexp.union(EXTENSIONS).source})\z/i => 0.9
|
8
10
|
}.freeze
|
9
11
|
|
10
|
-
TITLE_REGEX = /licen[sc]e:?/i
|
11
|
-
UNDERLINE_REGEX = /\n[-=]+/m
|
12
|
+
TITLE_REGEX = /licen[sc]e:?/i.freeze
|
13
|
+
UNDERLINE_REGEX = /\n[-=]+/m.freeze
|
12
14
|
CONTENT_REGEX = /^
|
13
15
|
(?: # Header lookbehind
|
14
16
|
[\#=]+\s#{TITLE_REGEX}\s*[\#=]* # Start of hashes or rdoc header
|
@@ -25,7 +27,7 @@ module Licensee
|
|
25
27
|
|
|
26
28
|
\z # End of file
|
27
29
|
)
|
28
|
-
/mix
|
30
|
+
/mix.freeze
|
29
31
|
|
30
32
|
def possible_matchers
|
31
33
|
super.push(Matchers::Reference)
|
data/lib/licensee/projects.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Filesystem-based project
|
2
4
|
#
|
3
5
|
# Analyze a folder on the filesystem for license information
|
@@ -36,6 +38,7 @@ module Licensee
|
|
36
38
|
relative_dir = Pathname.new(dir).relative_path_from(dir_path).to_s
|
37
39
|
Dir.glob(::File.join(dir, @pattern).tr('\\', '/')).map do |file|
|
38
40
|
next unless ::File.file?(file)
|
41
|
+
|
39
42
|
{ name: ::File.basename(file), dir: relative_dir }
|
40
43
|
end.compact
|
41
44
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Git-based project
|
2
4
|
#
|
3
5
|
# Analyze a given (bare) Git repository for license information
|
@@ -11,34 +13,40 @@ autoload :Rugged, 'rugged'
|
|
11
13
|
module Licensee
|
12
14
|
module Projects
|
13
15
|
class GitProject < Licensee::Projects::Project
|
14
|
-
attr_reader :
|
16
|
+
attr_reader :revision
|
15
17
|
|
16
18
|
class InvalidRepository < ArgumentError; end
|
17
19
|
|
18
20
|
def initialize(repo, revision: nil, **args)
|
19
|
-
@
|
20
|
-
repo
|
21
|
-
else
|
22
|
-
Rugged::Repository.new(repo)
|
23
|
-
end
|
24
|
-
|
21
|
+
@raw_repo = repo
|
25
22
|
@revision = revision
|
23
|
+
|
24
|
+
raise InvalidRepository if repository.head_unborn?
|
25
|
+
|
26
26
|
super(**args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def repository
|
30
|
+
@repository ||= begin
|
31
|
+
return @raw_repo if @raw_repo.is_a? Rugged::Repository
|
32
|
+
|
33
|
+
Rugged::Repository.new(@raw_repo)
|
34
|
+
end
|
27
35
|
rescue Rugged::OSError, Rugged::RepositoryError
|
28
36
|
raise InvalidRepository
|
29
37
|
end
|
30
38
|
|
31
39
|
def close
|
32
|
-
|
40
|
+
repository.close
|
33
41
|
end
|
34
42
|
|
35
43
|
private
|
36
44
|
|
37
45
|
def commit
|
38
46
|
@commit ||= if revision
|
39
|
-
|
40
|
-
|
41
|
-
|
47
|
+
repository.lookup(revision)
|
48
|
+
else
|
49
|
+
repository.last_commit
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# GitHub project
|
2
4
|
#
|
3
5
|
# Analyses a remote GitHub repository for license information
|
@@ -13,13 +15,14 @@ module Licensee
|
|
13
15
|
# If there's any trailing data (e.g. `.git`) this pattern will ignore it:
|
14
16
|
# we're going to use the API rather than clone the repo.
|
15
17
|
GITHUB_REPO_PATTERN =
|
16
|
-
%r{https://github.com/([^\/]+\/([^\/]+(?=\.git)|[^\/]+)).*}
|
18
|
+
%r{https://github.com/([^\/]+\/([^\/]+(?=\.git)|[^\/]+)).*}.freeze
|
17
19
|
|
18
20
|
class RepoNotFound < StandardError; end
|
19
21
|
|
20
22
|
def initialize(github_url, **args)
|
21
23
|
@repo = github_url[GITHUB_REPO_PATTERN, 1]
|
22
24
|
raise ArgumentError, "Not a github URL: #{github_url}" unless @repo
|
25
|
+
|
23
26
|
super(**args)
|
24
27
|
end
|
25
28
|
|
@@ -29,8 +32,10 @@ module Licensee
|
|
29
32
|
|
30
33
|
def files
|
31
34
|
return @files if defined? @files_from_tree
|
35
|
+
|
32
36
|
@files = dir_files
|
33
37
|
return @files unless @files.empty?
|
38
|
+
|
34
39
|
msg = "Could not load GitHub repo #{repo}, it may be private or deleted"
|
35
40
|
raise RepoNotFound, msg
|
36
41
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Licensee::Project represents an open source project on disk
|
2
4
|
# It is not used directly, but rather is extended by FSProject and GitProject
|
3
5
|
# depending on the type of file system access available
|
@@ -21,10 +23,11 @@ module Licensee
|
|
21
23
|
# Returns the matching License instance if a license can be detected
|
22
24
|
def license
|
23
25
|
return @license if defined? @license
|
26
|
+
|
24
27
|
@license = if licenses_without_copyright.count == 1 || lgpl?
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
licenses_without_copyright.first
|
29
|
+
elsif licenses_without_copyright.count > 1
|
30
|
+
Licensee::License.find('other')
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -53,6 +56,7 @@ module Licensee
|
|
53
56
|
def license_files
|
54
57
|
@license_files ||= begin
|
55
58
|
return [] if files.empty? || files.nil?
|
59
|
+
|
56
60
|
files = find_files do |n|
|
57
61
|
Licensee::ProjectFiles::LicenseFile.name_score(n)
|
58
62
|
end
|
@@ -67,6 +71,7 @@ module Licensee
|
|
67
71
|
def readme_file
|
68
72
|
return unless detect_readme?
|
69
73
|
return @readme if defined? @readme
|
74
|
+
|
70
75
|
@readme = begin
|
71
76
|
content, file = find_file do |n|
|
72
77
|
Licensee::ProjectFiles::ReadmeFile.name_score(n)
|
@@ -74,6 +79,7 @@ module Licensee
|
|
74
79
|
content = Licensee::ProjectFiles::ReadmeFile.license_content(content)
|
75
80
|
|
76
81
|
return unless content && file
|
82
|
+
|
77
83
|
Licensee::ProjectFiles::ReadmeFile.new(content, file)
|
78
84
|
end
|
79
85
|
end
|
@@ -82,12 +88,14 @@ module Licensee
|
|
82
88
|
def package_file
|
83
89
|
return unless detect_packages?
|
84
90
|
return @package_file if defined? @package_file
|
91
|
+
|
85
92
|
@package_file = begin
|
86
93
|
content, file = find_file do |n|
|
87
94
|
Licensee::ProjectFiles::PackageManagerFile.name_score(n)
|
88
95
|
end
|
89
96
|
|
90
97
|
return unless content && file
|
98
|
+
|
91
99
|
Licensee::ProjectFiles::PackageManagerFile.new(content, file)
|
92
100
|
end
|
93
101
|
end
|
@@ -96,6 +104,7 @@ module Licensee
|
|
96
104
|
|
97
105
|
def lgpl?
|
98
106
|
return false unless licenses.count == 2 && license_files.count == 2
|
107
|
+
|
99
108
|
license_files[0].lgpl? && license_files[1].gpl?
|
100
109
|
end
|
101
110
|
|
@@ -104,8 +113,9 @@ module Licensee
|
|
104
113
|
# sorted by file score descending
|
105
114
|
def find_files
|
106
115
|
return [] if files.empty? || files.nil?
|
116
|
+
|
107
117
|
found = files.map { |file| file.merge(score: yield(file[:name])) }
|
108
|
-
found.select! { |file| file[:score]
|
118
|
+
found.select! { |file| file[:score].positive? }
|
109
119
|
found.sort { |a, b| b[:score] <=> a[:score] }
|
110
120
|
end
|
111
121
|
|
@@ -114,6 +124,7 @@ module Licensee
|
|
114
124
|
# or nil, if no file scored > 0
|
115
125
|
def find_file(&block)
|
116
126
|
return if files.empty? || files.nil?
|
127
|
+
|
117
128
|
file = find_files(&block).first
|
118
129
|
[load_file(file), file] if file
|
119
130
|
end
|
@@ -128,7 +139,7 @@ module Licensee
|
|
128
139
|
# Returns an array of LicenseFiles with LPGL first
|
129
140
|
def prioritize_lgpl(files)
|
130
141
|
return files if files.empty?
|
131
|
-
return files unless files.first.license
|
142
|
+
return files unless files.first.license&.gpl?
|
132
143
|
|
133
144
|
lesser = files.find_index(&:lgpl?)
|
134
145
|
files.unshift(files.delete_at(lesser)) if lesser
|
data/lib/licensee/rule.rb
CHANGED
data/lib/licensee/version.rb
CHANGED
data/licensee.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/licensee/version', __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'licensee'
|
7
|
+
gem.version = Licensee::VERSION
|
8
|
+
|
9
|
+
gem.summary = 'A Ruby Gem to detect open source project licenses'
|
10
|
+
gem.description = <<-DESC
|
11
|
+
Licensee automates the process of reading LICENSE files and
|
12
|
+
compares their contents to known licenses using a fancy maths.
|
13
|
+
DESC
|
14
|
+
|
15
|
+
gem.authors = ['Ben Balter']
|
16
|
+
gem.email = 'ben.balter@github.com'
|
17
|
+
gem.homepage = 'https://github.com/benbalter/licensee'
|
18
|
+
gem.license = 'MIT'
|
19
|
+
|
20
|
+
gem.bindir = 'bin'
|
21
|
+
gem.executables << 'licensee'
|
22
|
+
|
23
|
+
gem.add_dependency('dotenv', '~> 2.0')
|
24
|
+
gem.add_dependency('octokit', '~> 4.17')
|
25
|
+
gem.add_dependency('reverse_markdown', '~> 1.0')
|
26
|
+
gem.add_dependency('rugged', '~> 0.24')
|
27
|
+
gem.add_dependency('thor', '~> 0.19')
|
28
|
+
|
29
|
+
gem.add_development_dependency('mustache', '>= 0.9', '< 2.0')
|
30
|
+
gem.add_development_dependency('pry', '~> 0.9')
|
31
|
+
gem.add_development_dependency('rake', '~> 10.3')
|
32
|
+
gem.add_development_dependency('rspec', '~> 3.5')
|
33
|
+
gem.add_development_dependency('rubocop', '~> 0.80')
|
34
|
+
gem.add_development_dependency('rubocop-performance', '~> 1.5')
|
35
|
+
gem.add_development_dependency('rubocop-rspec', '~> 1.36')
|
36
|
+
gem.add_development_dependency('simplecov', '~> 0.16')
|
37
|
+
gem.add_development_dependency('webmock', '~> 3.1')
|
38
|
+
|
39
|
+
gem.required_ruby_version = '> 2.3'
|
40
|
+
|
41
|
+
# ensure the gem is built out of versioned files
|
42
|
+
gem.files = Dir[
|
43
|
+
'Rakefile',
|
44
|
+
'{bin,lib,man,test,vendor,spec}/**/*',
|
45
|
+
'README*', 'LICENSE*'
|
46
|
+
] & `git ls-files -z`.split("\0")
|
47
|
+
end
|
data/spec/bin_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe 'command line invocation' do
|
2
4
|
let(:command) { ['bundle', 'exec', 'bin/licensee', 'help'] }
|
3
5
|
let(:arguments) { [] }
|
@@ -12,7 +14,7 @@ RSpec.describe 'command line invocation' do
|
|
12
14
|
let(:status) { output[2] }
|
13
15
|
|
14
16
|
it 'Returns a zero exit code' do
|
15
|
-
expect(status.exitstatus).to
|
17
|
+
expect(status.exitstatus).to be(0)
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'returns the help text' do
|