Class: GithubFlowCli::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/github_flow_cli/local.rb

Class Method Summary collapse

Class Method Details

.gitObject



20
21
22
# File 'lib/github_flow_cli/local.rb', line 20

def git
  @git ||= Git.open(git_dir)
end

.git_dirObject



24
25
26
27
28
29
30
31
# 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

.repoObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# 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