mirror of https://github.com/licensee/licensee.git
abstract github project
This commit is contained in:
parent
859da27c23
commit
e7bf382648
|
@ -28,10 +28,10 @@ module Licensee
|
|||
private
|
||||
|
||||
def files
|
||||
@files ||= contents.map { |data| { name: data[:name], dir: '/' } }
|
||||
@files ||= dir_files
|
||||
rescue Octokit::NotFound
|
||||
raise RepoNotFound,
|
||||
"Could not load GitHub repo #{repo}, it may be private or deleted"
|
||||
msg = "Could not load GitHub repo #{repo}, it may be private or deleted"
|
||||
raise RepoNotFound, msg
|
||||
end
|
||||
|
||||
def load_file(file)
|
||||
|
@ -39,8 +39,11 @@ module Licensee
|
|||
accept: 'application/vnd.github.v3.raw')
|
||||
end
|
||||
|
||||
def contents
|
||||
Octokit.contents(@repo).select { |data| data[:type] == 'file' }
|
||||
def dir_files(path = nil)
|
||||
files = Octokit.contents(@repo, path: path)
|
||||
files = files.select { |data| data[:type] == 'file' }
|
||||
files.each { |data| data[:dir] = File.dirname(data[:path]) }
|
||||
files.map(&:to_h)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# Using a `.gemspec` extension here breaks the `gem release` command
|
||||
Gem::Specification.new do |gem|
|
||||
gem.name = "licensee-fixture-project"
|
||||
gem.license = 'mit'
|
||||
end
|
|
@ -27,7 +27,7 @@
|
|||
FileUtils.rm_rf File.expand_path '.git', path
|
||||
end
|
||||
elsif described_class == Licensee::Projects::GitHubProject
|
||||
let(:path) do
|
||||
before do
|
||||
stub_request(
|
||||
:get, "#{api_base}/#{stubbed_org}/#{fixture}/contents/"
|
||||
).to_return(
|
||||
|
@ -43,9 +43,8 @@
|
|||
.with(headers: { 'accept' => 'application/vnd.github.v3.raw' })
|
||||
.to_return(status: 200, body: File.read(file))
|
||||
end
|
||||
|
||||
"https://github.com/#{stubbed_org}/#{fixture}"
|
||||
end
|
||||
let(:path) { "https://github.com/#{stubbed_org}/#{fixture}" }
|
||||
end
|
||||
|
||||
if described_class == Licensee::Projects::GitProject
|
||||
|
@ -178,6 +177,25 @@
|
|||
end
|
||||
end
|
||||
|
||||
if described_class == Licensee::Projects::GitHubProject
|
||||
before do
|
||||
stub_request(
|
||||
:get, "#{api_base}/#{stubbed_org}/#{fixture}/contents/"
|
||||
).to_return(
|
||||
status: 200,
|
||||
body: fixture_root_contents_from_api(fixture),
|
||||
headers: { 'Content-Type' => 'application/json' }
|
||||
)
|
||||
|
||||
file = fixture_path "#{fixture}/project.gemspec"
|
||||
relative_path = File.basename(file)
|
||||
parts = [api_base, stubbed_org, fixture, 'contents', relative_path]
|
||||
stub_request(:get, parts.join('/'))
|
||||
.with(headers: { 'accept' => 'application/vnd.github.v3.raw' })
|
||||
.to_return(status: 200, body: File.read(file))
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm("#{fixture_path(fixture)}/project.gemspec")
|
||||
end
|
||||
|
|
|
@ -43,7 +43,8 @@ def fixture_root_contents_from_api(fixture)
|
|||
fixture_root_files(fixture).map do |file|
|
||||
{
|
||||
name: File.basename(file),
|
||||
type: 'file'
|
||||
type: 'file',
|
||||
path: File.basename(file)
|
||||
}
|
||||
end.to_json
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue