class GitHttpsable::Push::Repository

Public Class Methods

new(path, options = {}) click to toggle source
# File lib/git_httpsable/push/repository.rb, line 4
def initialize(path, options = {})
  @path = path
  @options = { log: logger }.merge(options)
end

Public Instance Methods

absolute_path(path) click to toggle source
# File lib/git_httpsable/push/repository.rb, line 75
def absolute_path(path)
  path.start_with?('/') ? path : '/' + path
end
env_git_access_token() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 49
def env_git_access_token
  ENV['GIT_SERVER_ACCESS_TOKEN']
end
env_github_access_token() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 45
def env_github_access_token
  ENV['GITHUB_ACCESS_TOKEN']
end
git() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 37
def git
  @git ||= ::Git.open(@path, @options)
end
host(host) click to toggle source
# File lib/git_httpsable/push/repository.rb, line 67
def host(host)
  ENV['GIT_SERVER_HOST'] || host
end
logger() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 33
def logger
  ::GitHttpsable::Push.logger
end
port() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 71
def port
  ENV['GIT_SERVER_PORT'] || nil
end
push(remote = 'origin', branch = 'master', options = {}) click to toggle source
# File lib/git_httpsable/push/repository.rb, line 9
def push(remote = 'origin', branch = 'master', options = {})
  logger.debug(remote: remote, branch: branch, options: options)
  # check current branch's upstream remote and branch?
  url = remote_url(remote)
  fail NotExistRemoteUrlError, %(no "#{remote}" url) unless url
  parsed = GitCloneUrl.parse(url)

  converted_url = \
    URI::Generic.build(
      scheme: scheme,
      userinfo: userinfo,
      host: host(parsed.host),
      port: port,
      path: absolute_path(parsed.path)
    )
  git.push(converted_url.to_s, branch, options)
rescue StandardError => e
  raise e if e.is_a?(GitHttpsablePushError)

  exception = GitHttpsablePushError.new('(' + e.class.name + ') ' + e.message)
  exception.set_backtrace(e.backtrace)
  raise exception
end
remote_url(remote) click to toggle source
# File lib/git_httpsable/push/repository.rb, line 41
def remote_url(remote)
  git.remote(remote) && git.remote(remote).url
end
scheme() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 63
def scheme
  ENV['GIT_SERVER_SCHEME'] || 'https'
end
userinfo() click to toggle source
# File lib/git_httpsable/push/repository.rb, line 53
def userinfo
  if env_git_access_token
    env_git_access_token
  elsif env_github_access_token
    "#{env_github_access_token}:x-oauth-basic"
  else
    fail NoAuthDataError
  end
end