licensee 4.3.1 → 4.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/licensee +3 -1
- data/lib/licensee/project.rb +21 -13
- data/lib/licensee/version.rb +1 -1
- data/test/fixtures/licence.git/HEAD +1 -0
- data/test/fixtures/licence.git/config +6 -0
- data/test/fixtures/licence.git/objects/66/0c086dc25f9f3b96e7afd9dee8a11b4e614543 +0 -0
- data/test/fixtures/licence.git/objects/68/804815597f79aa323de3257a8fd7b76449943c +0 -0
- data/test/fixtures/licence.git/objects/dd/59aed84c5aa4dff7ceda11a1c045f831194067 +0 -0
- data/test/fixtures/licence.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/licence.git/refs/heads/master +1 -0
- data/test/test_licensee_project.rb +21 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01e0662cd476d9f2a5e8764fb2c0147166da2cb
|
4
|
+
data.tar.gz: bdf3c4a1438ae6001693c58ed8be7ed04b6ecd53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a8f8837bd03de8ce8f5da7a05d2b781d2c0a51a0df2bbd2b598a372e7fed77309097a81f7ba1a291315161f4b8ed360c9be924e9d86eed48648b7762e64389
|
7
|
+
data.tar.gz: 0aa65b6e811f06047422f1676f79f458674b78e74065de526ed82c8d77e99f29afccf9588813494757cf885fd489c166b5224cce60ab23be0dd80c1a600bbcde
|
data/bin/licensee
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require_relative "../lib/licensee"
|
4
|
-
|
4
|
+
project = Licensee::Project.new(Dir.pwd)
|
5
|
+
license = project.license_file
|
5
6
|
|
6
7
|
if license
|
8
|
+
puts "License file: #{project.send(:license_blob)[:name]}"
|
7
9
|
puts "License: #{license.match ? license.match.meta['title'] : 'no license'}"
|
8
10
|
puts "Confidence: #{license.confidence}%"
|
9
11
|
puts "Method: #{license.matcher.class}"
|
data/lib/licensee/project.rb
CHANGED
@@ -26,26 +26,34 @@ class Licensee
|
|
26
26
|
@revision = revision
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
30
|
-
# Returns a Licensee::LicenseFile instance
|
29
|
+
# Returns an instance of Licensee::LicenseFile if there's a license file detected
|
31
30
|
def license_file
|
32
|
-
|
31
|
+
@license_file ||= LicenseFile.new(@repository.lookup(license_blob[:oid])) if license_blob
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# Returns the matching Licensee::License instance if a license can be detected
|
35
|
+
def license
|
36
|
+
@license ||= license_file.match if license_file
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
license_blob = tree.find { |blob| LICENSE_FILENAMES.include? blob[:name].downcase }
|
39
|
+
private
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
def commit
|
42
|
+
@revision ? @repository.lookup(@revision) : @repository.last_commit
|
43
|
+
end
|
42
44
|
|
43
|
-
|
45
|
+
def tree
|
46
|
+
commit.tree.select { |blob| blob[:type] == :blob }
|
44
47
|
end
|
45
48
|
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
+
# Detects the license file, if any
|
50
|
+
# Returns the blob hash as detected in the tree
|
51
|
+
def license_blob
|
52
|
+
# Prefer an exact match to one of our known file names
|
53
|
+
license_blob = tree.find { |blob| LICENSE_FILENAMES.include? blob[:name].downcase }
|
54
|
+
|
55
|
+
# Fall back to the first file in the project root that has the word license in it
|
56
|
+
license_blob || tree.find { |blob| blob[:name] =~ /licen(s|c)e/i }
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
data/lib/licensee/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
ref: refs/heads/master
|
@@ -0,0 +1 @@
|
|
1
|
+
660c086dc25f9f3b96e7afd9dee8a11b4e614543
|
@@ -14,6 +14,22 @@ class TestLicenseeProject < Minitest::Test
|
|
14
14
|
assert_equal "mit", @project.license.key
|
15
15
|
end
|
16
16
|
|
17
|
+
should "know the last commit" do
|
18
|
+
commit = @project.send(:commit)
|
19
|
+
assert_equal Rugged::Commit, commit.class
|
20
|
+
assert_equal "b02cbad9d254c41d16d56ed9d6d2cf07c1d837fd", commit.oid
|
21
|
+
end
|
22
|
+
|
23
|
+
should "retrieve the tree" do
|
24
|
+
tree = @project.send(:tree)
|
25
|
+
assert_equal 1, tree.count
|
26
|
+
assert_equal "bcb552d06d9cf1cd4c048a6d3bf716849c2216cc", tree.first[:oid]
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return the license blob" do
|
30
|
+
assert_equal "LICENSE", @project.send(:license_blob)[:name]
|
31
|
+
end
|
32
|
+
|
17
33
|
should "detect an atypically cased license file" do
|
18
34
|
project = Licensee::Project.new fixture_path("case-sensitive.git")
|
19
35
|
assert_equal Licensee::LicenseFile, project.license_file.class
|
@@ -33,4 +49,9 @@ class TestLicenseeProject < Minitest::Test
|
|
33
49
|
project = Licensee::Project.new fixture_path("license-folder.git")
|
34
50
|
assert_equal nil, project.license
|
35
51
|
end
|
52
|
+
|
53
|
+
should "detect licence files" do
|
54
|
+
project = Licensee::Project.new fixture_path("licence.git")
|
55
|
+
assert_equal "mit", project.license.key
|
56
|
+
end
|
36
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -122,6 +122,13 @@ files:
|
|
122
122
|
- test/fixtures/case-sensitive.git/objects/2c/b878e0851c5cf53d7455d9018baa6755a38bd7
|
123
123
|
- test/fixtures/case-sensitive.git/objects/fb/ddf40ba5f30225af7cd9841afe374ca5800cb9
|
124
124
|
- test/fixtures/case-sensitive.git/refs/heads/master
|
125
|
+
- test/fixtures/licence.git/HEAD
|
126
|
+
- test/fixtures/licence.git/config
|
127
|
+
- test/fixtures/licence.git/objects/66/0c086dc25f9f3b96e7afd9dee8a11b4e614543
|
128
|
+
- test/fixtures/licence.git/objects/68/804815597f79aa323de3257a8fd7b76449943c
|
129
|
+
- test/fixtures/licence.git/objects/dd/59aed84c5aa4dff7ceda11a1c045f831194067
|
130
|
+
- test/fixtures/licence.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
131
|
+
- test/fixtures/licence.git/refs/heads/master
|
125
132
|
- test/fixtures/license-folder.git/HEAD
|
126
133
|
- test/fixtures/license-folder.git/config
|
127
134
|
- test/fixtures/license-folder.git/objects/32/6d0761f0c54d54327ea9e127e02d9bae14d2c8
|