lib/licensee/projects/github_project.rb in licensee-9.9.3 vs lib/licensee/projects/github_project.rb in licensee-9.9.4

- old
+ new

@@ -26,22 +26,37 @@ attr_reader :repo private def files - @files ||= contents.map { |data| { name: data[:name], dir: '/' } } - rescue Octokit::NotFound - raise RepoNotFound, - "Could not load GitHub repo #{repo}, it may be private or deleted" + return @files if defined? @files_from_tree + @files = dir_files + return @files unless @files.empty? + msg = "Could not load GitHub repo #{repo}, it may be private or deleted" + raise RepoNotFound, msg end def load_file(file) - Octokit.contents(@repo, path: file[:name], - accept: 'application/vnd.github.v3.raw') + client.contents(@repo, path: file[:path], + accept: 'application/vnd.github.v3.raw').to_s end - def contents - Octokit.contents(@repo).select { |data| data[:type] == 'file' } + def dir_files(path = nil) + path = path.gsub('./', '') if path + files = client.contents(@repo, path: path) + files = files.select { |data| data[:type] == 'file' } + files.each { |data| data[:dir] = File.dirname(data[:path]) } + files.map(&:to_h) + rescue Octokit::NotFound + [] + end + + def client + @client ||= Octokit::Client.new access_token: access_token + end + + def access_token + ENV['OCTOKIT_ACCESS_TOKEN'] end end end end