Class: Vpr::GitParser

Inherits:
Object
  • Object
show all
Defined in:
lib/vpr/git_parser.rb

Constant Summary collapse

REGEXP =
%r{
(?<protocol>(http://|https://|git://|ssh://))*
  (?<username>[^@]+@)*
  (?<host>[^/]+)
[/:]
(?<owner>[^/]+)
/
(?<repo>[^\/]+[^(.git)])
}x.freeze

Class Method Summary collapse

Class Method Details

.current_branchObject



24
25
26
27
# File 'lib/vpr/git_parser.rb', line 24

def current_branch
  git = Git.open(git_dir)
  git.current_branch
end

.hostObject



29
30
31
32
33
34
# File 'lib/vpr/git_parser.rb', line 29

def host
  remote_uri = remotes[Configuration.remote]
  matched = remote_uri.match(REGEXP)

  matched[:host]
end

.repo_urlObject



17
18
19
20
21
22
# File 'lib/vpr/git_parser.rb', line 17

def repo_url
  remote_uri = remotes[Configuration.remote]
  matched = remote_uri.match(REGEXP)

  File.join("https://#{matched[:host]}", matched[:owner], matched[:repo])
end