Class: Zubat::CLI::App::GitRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/zubat/cli/app.rb

Constant Summary collapse

URL_FORMATS =
[
  %r[https://(.+)/(.+)/(.+).git],
  %r[git@(.+):(.+)/(.+).git],
  %r[ssh://(.+)/(.+)/(.+)],
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname:, org:, repo:) ⇒ GitRepo

Returns a new instance of GitRepo.



46
47
48
49
50
# File 'lib/zubat/cli/app.rb', line 46

def initialize(hostname:, org:, repo:)
  @hostname = hostname
  @org = org
  @repo = repo
end

Class Method Details

.guessObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zubat/cli/app.rb', line 34

def self.guess
  url = GitCommandWrapper.new.remote_origin_url

  matched = URL_FORMATS
    .find { |format| format.match?(url) }
    &.match(url)

  return unless matched

  new(hostname: matched[1], org: matched[2], repo: matched[3])
end

Instance Method Details

#site_urlObject



52
53
54
# File 'lib/zubat/cli/app.rb', line 52

def site_url
  "https://#{@hostname}/#{@org}/#{@repo}"
end