Class: PullRequest::Create::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/pull_request/create/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Repository

Returns a new instance of Repository.



4
5
6
7
# File 'lib/pull_request/create/repository.rb', line 4

def initialize(path, options = {})
  @path = path
  @options = options
end

Instance Method Details

#current_branchObject



17
18
19
# File 'lib/pull_request/create/repository.rb', line 17

def current_branch
  git.current_branch
end

#gitObject



13
14
15
# File 'lib/pull_request/create/repository.rb', line 13

def git
  @git ||= ::Git.open(@path, @options)
end

#loggerObject



9
10
11
# File 'lib/pull_request/create/repository.rb', line 9

def logger
  ::PullRequest::Create.logger
end

#remote_urlsObject



30
31
32
33
34
# File 'lib/pull_request/create/repository.rb', line 30

def remote_urls
  git
    .remotes
    .map(&:url)
end

#slugObject



21
22
23
24
25
26
27
28
# File 'lib/pull_request/create/repository.rb', line 21

def slug
  slug_regex = %r{\A/?(?<slug>.*?)(?:\.git)?\Z}
  remote_urls.map do |url|
    uri = GitCloneUrl.parse(url)
    match = slug_regex.match(uri.path)
    match[:slug] if match
  end.compact.first
end