Class: Geet::Git::Repository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/geet/git/repository.rb

Overview

This class represents, for convenience, both the local and the remote repository, but the remote code is separated in each provider module.

Constant Summary collapse

DOMAIN_PROVIDERS_MAPPING =
{
  'github.com' => Geet::GitHub
}.freeze
REMOTE_ORIGIN_REGEX =

For simplicity, we match any character except the ones the separators.

%r{\Agit@([^:]+):([^/]+)/(.*?)(\.git)?\Z}

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ Repository



30
31
32
33
34
35
36
37
38
# File 'lib/geet/git/repository.rb', line 30

def initialize(api_token)
  the_provider_domain = provider_domain
  provider_module = DOMAIN_PROVIDERS_MAPPING[the_provider_domain] || raise("Provider not supported for domain: #{provider_domain}")

  api_helper = provider_module::ApiHelper.new(api_token, user, owner, repo)

  @remote_repository = provider_module::RemoteRepository.new(self, api_helper)
  @account = provider_module::.new(api_helper)
end

Instance Method Details

#current_headObject

DATA



60
61
62
# File 'lib/geet/git/repository.rb', line 60

def current_head
  `git rev-parse --abbrev-ref HEAD`.strip
end

#ownerObject



50
51
52
# File 'lib/geet/git/repository.rb', line 50

def owner
  remote_origin[REMOTE_ORIGIN_REGEX, 2]
end

#provider_domainObject



46
47
48
# File 'lib/geet/git/repository.rb', line 46

def provider_domain
  remote_origin[REMOTE_ORIGIN_REGEX, 1]
end

#repoObject



54
55
56
# File 'lib/geet/git/repository.rb', line 54

def repo
  remote_origin[REMOTE_ORIGIN_REGEX, 3]
end

#userObject

METADATA



42
43
44
# File 'lib/geet/git/repository.rb', line 42

def user
  `git config --get user.email`.strip
end