class Ruboty::Handlers::Bundler::Client

Constants

DEFAULT_GITHUB_HOST

Public Class Methods

new(access_token: nil) click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 86
def initialize(access_token: nil)
  @access_token = access_token
end

Public Instance Methods

get(path) click to toggle source

@param path [String] File path (e.g. “Gemfile”) @return [String] File content

# File lib/ruboty/handlers/bundler.rb, line 92
def get(path)
  cache[path] ||= octokit_client.contents(repository, path: path)
end
update(path, content) click to toggle source

@param path [String] File path (e.g. “Gemfile”) @param content [String] File content

# File lib/ruboty/handlers/bundler.rb, line 98
def update(path, content)
  octokit_client.update_contents(
    repository,
    path,
    "Update #{path}",
    get(path)[:sha],
    content,
  )
end

Private Instance Methods

api_endpoint() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 110
def api_endpoint
  "https://#{github_host}/api/v3" if github_host
end
cache() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 114
def cache
  @cache ||= {}
end
github_host() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 118
def github_host
  ENV["GITHUB_HOST"]
end
octokit_client() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 122
def octokit_client
  @octokit_client ||= Octokit::Client.new(
    {
      access_token: @access_token,
      api_endpoint: api_endpoint,
      web_endpoint: web_endpoint,
    }.reject do |key, value|
      value.nil?
    end
  )
end
repository() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 134
def repository
  ENV["RUBOTY_BUNDLER_REPOSITORY"]
end
web_endpoint() click to toggle source
# File lib/ruboty/handlers/bundler.rb, line 138
def web_endpoint
  "https://#{github_host || DEFAULT_GITHUB_HOST}/"
end