licensee 4.7.0 → 4.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/licensee/license.rb +7 -1
- data/lib/licensee/project.rb +9 -29
- data/lib/licensee/version.rb +1 -1
- data/test/fixtures/licenses.git/objects/51/a11d50f29a14774ded8f7b90ba9938dce78a92 +3 -0
- data/test/fixtures/licenses.git/objects/5e/df454e6517673d5e64a33cf284308b9c6b1075 +0 -0
- data/test/fixtures/licenses.git/objects/e1/b4dc13f4bf683ce8f2943e051c3e91e778d043 +0 -0
- data/test/fixtures/licenses.git/refs/heads/master +1 -0
- data/test/test_licensee_project.rb +22 -35
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c12d9b4200c5da5e7b8d9de112cfac32f52d3def
|
4
|
+
data.tar.gz: 81a13ed9b414494093be1ebe79a52aa3008a7d99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9913ceaf83583b2fa47ffd0389af8e2aaa8219a3efd9243fa01d03a692c35cb4529b482f71ed347e034c549ee8e700aba93c0105c6e13dfa873ee6750cad003b
|
7
|
+
data.tar.gz: 3814c71d59f4df84abff4204213130732342b578e06212e0ee9dec632c83ac46f8e0542a1f6deb14513639f7556ddcf04191b676cfcb46471d53404fa8d99504
|
data/lib/licensee/license.rb
CHANGED
@@ -30,7 +30,13 @@ class Licensee
|
|
30
30
|
|
31
31
|
# License metadata from YAML front matter
|
32
32
|
def meta
|
33
|
-
@meta ||=
|
33
|
+
@meta ||= if parts && parts[1]
|
34
|
+
if YAML.respond_to? :safe_yaml
|
35
|
+
YAML.safe_load(parts[1])
|
36
|
+
else
|
37
|
+
YAML.load(parts[1])
|
38
|
+
end
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
# Returns the human-readable license name
|
data/lib/licensee/project.rb
CHANGED
@@ -38,13 +38,15 @@ class Licensee
|
|
38
38
|
#
|
39
39
|
# filename - (string) the name of the file to score
|
40
40
|
#
|
41
|
-
# Returns 1
|
42
|
-
#
|
43
|
-
# Returns 0
|
41
|
+
# Returns 1.0 if the file is definately a license file
|
42
|
+
# Returns 0.75 if the file is probably a license file
|
43
|
+
# Returns 0.5 if the file is likely a license file
|
44
|
+
# Returns 0.0 if the file is definately not a license file
|
44
45
|
def self.match_license_file(filename)
|
45
|
-
return 1
|
46
|
-
return 0.
|
47
|
-
return 0
|
46
|
+
return 1.0 if filename =~ /\A(un)?licen[sc]e(\.[^.]+)?\z/i
|
47
|
+
return 0.75 if filename =~ /\Acopy(ing|right)(\.[^.]+)?\z/i
|
48
|
+
return 0.5 if filename =~ /licen[sc]e/i
|
49
|
+
return 0.0
|
48
50
|
end
|
49
51
|
|
50
52
|
private
|
@@ -60,8 +62,7 @@ class Licensee
|
|
60
62
|
# Detects the license file, if any
|
61
63
|
# Returns the blob hash as detected in the tree
|
62
64
|
def license_hash
|
63
|
-
|
64
|
-
license_hash ||= tree.find { |blob| self.class.maybe_license_file?(blob[:name]) }
|
65
|
+
tree.sort_by { |blob| self.class.match_license_file(blob[:name]) }.last
|
65
66
|
end
|
66
67
|
|
67
68
|
def license_blob
|
@@ -71,26 +72,5 @@ class Licensee
|
|
71
72
|
def license_path
|
72
73
|
license_hash[:name] if license_hash
|
73
74
|
end
|
74
|
-
|
75
|
-
# Regex to detect license files
|
76
|
-
#
|
77
|
-
# Examples it should match:
|
78
|
-
# - LICENSE.md
|
79
|
-
# - licence.txt
|
80
|
-
# - unlicense
|
81
|
-
# - copying
|
82
|
-
# - copyright
|
83
|
-
def self.license_file?(filename)
|
84
|
-
!!(filename =~ /\A(un)?licen[sc]e|copy(ing|right)(\.[^.]+)?\z/i)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Regex to detect things that look like license files
|
88
|
-
#
|
89
|
-
# Examples it should match:
|
90
|
-
# - license-MIT.txt
|
91
|
-
# - MIT-LICENSE
|
92
|
-
def self.maybe_license_file?(filename)
|
93
|
-
!!(filename =~ /licen[sc]e/i)
|
94
|
-
end
|
95
75
|
end
|
96
76
|
end
|
data/lib/licensee/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
51a11d50f29a14774ded8f7b90ba9938dce78a92
|
@@ -79,42 +79,29 @@ class TestLicenseeProject < Minitest::Test
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
context "license filename
|
83
|
-
|
84
|
-
|
85
|
-
"
|
86
|
-
"LICENCE",
|
87
|
-
"license.md",
|
88
|
-
"
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"
|
92
|
-
"
|
93
|
-
|
94
|
-
|
95
|
-
|
82
|
+
context "license filename scoring" do
|
83
|
+
|
84
|
+
EXPECTATIONS = {
|
85
|
+
"license" => 1.0,
|
86
|
+
"LICENCE" => 1.0,
|
87
|
+
"license.md" => 1.0,
|
88
|
+
"LICENSE.md" => 1.0,
|
89
|
+
"license.txt" => 1.0,
|
90
|
+
"unLICENSE" => 1.0,
|
91
|
+
"unlicence" => 1.0,
|
92
|
+
"COPYING" => 0.75,
|
93
|
+
"copyRIGHT" => 0.75,
|
94
|
+
"COPYRIGHT.txt" => 0.75,
|
95
|
+
"LICENSE-MIT" => 0.5,
|
96
|
+
"MIT-LICENSE.txt" => 0.5,
|
97
|
+
"mit-license-foo.md" => 0.5,
|
98
|
+
"README.txt" => 0.0
|
99
|
+
}
|
100
|
+
|
101
|
+
EXPECTATIONS.each do |filename, expected|
|
102
|
+
should "score a license named `#{filename}` as `#{expected}`" do
|
103
|
+
assert_equal expected, Licensee::Project.match_license_file(filename)
|
96
104
|
end
|
97
105
|
end
|
98
|
-
|
99
|
-
should "not match MIT-LICENSE" do
|
100
|
-
refute Licensee::Project.license_file?("MIT-LICENSE")
|
101
|
-
end
|
102
|
-
|
103
|
-
# Abnormal license names
|
104
|
-
[
|
105
|
-
"LICENSE-MIT",
|
106
|
-
"MIT-LICENSE.txt",
|
107
|
-
"mit-license-foo.md"
|
108
|
-
].each do |license|
|
109
|
-
should "match #{license}" do
|
110
|
-
assert Licensee::Project.maybe_license_file?(license)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
should "return the proper license files scores" do
|
115
|
-
assert_equal 1, Licensee::Project.match_license_file("LICENSE.md")
|
116
|
-
assert_equal 0.5, Licensee::Project.match_license_file("MIT-LICENSE")
|
117
|
-
assert_equal 0, Licensee::Project.match_license_file("README.txt")
|
118
|
-
end
|
119
106
|
end
|
120
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.7.
|
4
|
+
version: 4.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
@@ -140,10 +140,14 @@ files:
|
|
140
140
|
- test/fixtures/license-folder.git/refs/heads/master
|
141
141
|
- test/fixtures/licenses.git/HEAD
|
142
142
|
- test/fixtures/licenses.git/config
|
143
|
+
- test/fixtures/licenses.git/objects/51/a11d50f29a14774ded8f7b90ba9938dce78a92
|
144
|
+
- test/fixtures/licenses.git/objects/5e/df454e6517673d5e64a33cf284308b9c6b1075
|
145
|
+
- test/fixtures/licenses.git/objects/e1/b4dc13f4bf683ce8f2943e051c3e91e778d043
|
143
146
|
- test/fixtures/licenses.git/objects/info/packs
|
144
147
|
- test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.idx
|
145
148
|
- test/fixtures/licenses.git/objects/pack/pack-4a7088171ae3ca900f010a4be6f1c2c96490c338.pack
|
146
149
|
- test/fixtures/licenses.git/packed-refs
|
150
|
+
- test/fixtures/licenses.git/refs/heads/master
|
147
151
|
- test/fixtures/named-license-file-prefix.git/HEAD
|
148
152
|
- test/fixtures/named-license-file-prefix.git/config
|
149
153
|
- test/fixtures/named-license-file-prefix.git/objects/64/3983d3f82ecc2a7d8e4227946220ebffd477d2
|