class GithubFlowCli::Local

Public Class Methods

git() click to toggle source
# File lib/github_flow_cli/local.rb, line 20
def git
  @git ||= Git.open(git_dir)
end
git_dir() click to toggle source
# File lib/github_flow_cli/local.rb, line 24
def git_dir
  current = File.expand_path('.')
  while !File.directory?(File.join(current, '.git'))
    current = File.dirname(current)
    break if current == '/'
  end
  current
end
repo() click to toggle source
# File lib/github_flow_cli/local.rb, line 6
def repo
  return @repo if @repo
  url = git.remote.url
  match = url&.match(%r{.*[:/](?<owner>.*?)/(?<name>.*?)(\.git)?$})
  return nil unless match && match[:owner] && match[:name]
  @repo = Octokit::Repository.from_url("/#{match[:owner]}/#{match[:name]}")
rescue ArgumentError => ex
  if ex.message =~ /path does not exist/
    nil
  else
    raise
  end
end