class Licensee::Projects::GitHubProject

Constants

GITHUB_REPO_PATTERN

If there’s any trailing data (e.g. ‘.git`) this pattern will ignore it: we’re going to use the API rather than clone the repo.

Attributes

repo[R]

Public Class Methods

new(github_url, **args) click to toggle source
Calls superclass method Licensee::Projects::Project::new
# File lib/licensee/projects/github_project.rb, line 22
def initialize(github_url, **args)
  @repo = github_url[GITHUB_REPO_PATTERN, 1]
  raise ArgumentError, "Not a github URL: #{github_url}" unless @repo

  super(**args)
end

Private Instance Methods

access_token() click to toggle source
# File lib/licensee/projects/github_project.rb, line 62
def access_token
  ENV['OCTOKIT_ACCESS_TOKEN']
end
client() click to toggle source
# File lib/licensee/projects/github_project.rb, line 58
def client
  @client ||= Octokit::Client.new access_token: access_token
end
dir_files(path = nil) click to toggle source
# File lib/licensee/projects/github_project.rb, line 48
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
files() click to toggle source
# File lib/licensee/projects/github_project.rb, line 33
def files
  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
load_file(file) click to toggle source
# File lib/licensee/projects/github_project.rb, line 43
def load_file(file)
  client.contents(@repo, path:   file[:path],
                         accept: 'application/vnd.github.v3.raw').to_s
end