licensee 9.9.3 → 9.9.4

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: 9d245d544a683bfaff9448e8654a409cea3b6ddc808ba7f7b966c84e031255ea
4
- data.tar.gz: 801c8048260b692571828fce99aa754afeb99063849e3e330e7fbb0b1b7117db
3
+ metadata.gz: b85ef478c3f4eee0b055871998df44b7ac925d4cf558b12257e4ece69dffb605
4
+ data.tar.gz: 605cc902e7c2ff5dce082c200a12f0758577757dc1c23f3b601aa1a033bce055
5
5
  SHA512:
6
- metadata.gz: 918b6abcf12b00722fb85c64112f2e11334a4b43d6f3b7d3335156a6bb21b0077432030f6c132aa0950af0b4860102a9a1c2d8548a5de5e1529852ae13e29ed1
7
- data.tar.gz: 919b0c1a4390a2dd964e7f4d245194ef47e108e1336fc4f04b9795a97f17475ebc64dce12ff1bbd97bb805f5d1fc95774ece1878af17a89f4d57cf974582944b
6
+ metadata.gz: e570922e52f88998432deea4760a3414aa583406cfdb77e156e474c076e82c6314edb2934caeb515d9c24217e6a06ab70909bef3898ff69fc03dd6c55ae99aa5
7
+ data.tar.gz: 970c89d645d161d59380c02934485bff1108fa0d31289975da3f8f87103949e18b1b12eb584291477170a530e833465339887d99a042b605f705a27ab3082512
@@ -43,7 +43,7 @@ module Licensee
43
43
 
44
44
  def matches
45
45
  @matches ||= matches_by_similarity.select do |_, similarity|
46
- similarity >= Licensee.confidence_threshold
46
+ similarity >= minimum_confidence
47
47
  end
48
48
  end
49
49
 
@@ -51,6 +51,12 @@ module Licensee
51
51
  def confidence
52
52
  @confidence ||= match ? file.similarity(match) : 0
53
53
  end
54
+
55
+ private
56
+
57
+ def minimum_confidence
58
+ Licensee.confidence_threshold
59
+ end
54
60
  end
55
61
  end
56
62
  end
@@ -28,19 +28,34 @@ module Licensee
28
28
  private
29
29
 
30
30
  def files
31
- @files ||= contents.map { |data| { name: data[:name], dir: '/' } }
32
- rescue Octokit::NotFound
33
- raise RepoNotFound,
34
- "Could not load GitHub repo #{repo}, it may be private or deleted"
31
+ return @files if defined? @files_from_tree
32
+ @files = dir_files
33
+ return @files unless @files.empty?
34
+ msg = "Could not load GitHub repo #{repo}, it may be private or deleted"
35
+ raise RepoNotFound, msg
35
36
  end
36
37
 
37
38
  def load_file(file)
38
- Octokit.contents(@repo, path: file[:name],
39
- accept: 'application/vnd.github.v3.raw')
39
+ client.contents(@repo, path: file[:path],
40
+ accept: 'application/vnd.github.v3.raw').to_s
41
+ end
42
+
43
+ def dir_files(path = nil)
44
+ path = path.gsub('./', '') if path
45
+ files = client.contents(@repo, path: path)
46
+ files = files.select { |data| data[:type] == 'file' }
47
+ files.each { |data| data[:dir] = File.dirname(data[:path]) }
48
+ files.map(&:to_h)
49
+ rescue Octokit::NotFound
50
+ []
51
+ end
52
+
53
+ def client
54
+ @client ||= Octokit::Client.new access_token: access_token
40
55
  end
41
56
 
42
- def contents
43
- Octokit.contents(@repo).select { |data| data[:type] == 'file' }
57
+ def access_token
58
+ ENV['OCTOKIT_ACCESS_TOKEN']
44
59
  end
45
60
  end
46
61
  end
@@ -1,3 +1,3 @@
1
1
  module Licensee
2
- VERSION = '9.9.3'.freeze
2
+ VERSION = '9.9.4'.freeze
3
3
  end
@@ -27,7 +27,7 @@
27
27
  FileUtils.rm_rf File.expand_path '.git', path
28
28
  end
29
29
  elsif described_class == Licensee::Projects::GitHubProject
30
- let(:path) do
30
+ before do
31
31
  stub_request(
32
32
  :get, "#{api_base}/#{stubbed_org}/#{fixture}/contents/"
33
33
  ).to_return(
@@ -43,9 +43,8 @@
43
43
  .with(headers: { 'accept' => 'application/vnd.github.v3.raw' })
44
44
  .to_return(status: 200, body: File.read(file))
45
45
  end
46
-
47
- "https://github.com/#{stubbed_org}/#{fixture}"
48
46
  end
47
+ let(:path) { "https://github.com/#{stubbed_org}/#{fixture}" }
49
48
  end
50
49
 
51
50
  if described_class == Licensee::Projects::GitProject
@@ -178,6 +177,25 @@
178
177
  end
179
178
  end
180
179
 
180
+ if described_class == Licensee::Projects::GitHubProject
181
+ before do
182
+ stub_request(
183
+ :get, "#{api_base}/#{stubbed_org}/#{fixture}/contents/"
184
+ ).to_return(
185
+ status: 200,
186
+ body: fixture_root_contents_from_api(fixture),
187
+ headers: { 'Content-Type' => 'application/json' }
188
+ )
189
+
190
+ file = fixture_path "#{fixture}/project.gemspec"
191
+ relative_path = File.basename(file)
192
+ parts = [api_base, stubbed_org, fixture, 'contents', relative_path]
193
+ stub_request(:get, parts.join('/'))
194
+ .with(headers: { 'accept' => 'application/vnd.github.v3.raw' })
195
+ .to_return(status: 200, body: File.read(file))
196
+ end
197
+ end
198
+
181
199
  after do
182
200
  FileUtils.rm("#{fixture_path(fixture)}/project.gemspec")
183
201
  end
@@ -43,7 +43,8 @@ def fixture_root_contents_from_api(fixture)
43
43
  fixture_root_files(fixture).map do |file|
44
44
  {
45
45
  name: File.basename(file),
46
- type: 'file'
46
+ type: 'file',
47
+ path: File.basename(file)
47
48
  }
48
49
  end.to_json
49
50
  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: 9.9.3
4
+ version: 9.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-23 00:00:00.000000000 Z
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv