Class: Lolcommits::GitInfo

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/lolcommits/git_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitInfo



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lolcommits/git_info.rb', line 11

def initialize
  debug 'GitInfo: attempting to read local repository'
  g    = Git.open('.')
  debug 'GitInfo: reading commits logs'
  commit = g.log.first
  debug "GitInfo: most recent commit is '#{commit}'"

  self.message = commit.message.split("\n").first
  self.sha     = commit.sha[0..10]
  self.repo_internal_path = g.repo.path
  self.url = remote_https_url(g.remote.url) if g.remote.url

  regex = /.*[:]([\/\w\-]*).git/
  match = g.remote.url.match regex if g.remote.url
  if match
    self.repo = match[1]
  elsif !g.repo.path.empty?
    self.repo = g.repo.path.split(File::SEPARATOR)[-2]
  end

  debug 'GitInfo: parsed the following values from commit:'
  debug "GitInfo: \t#{self.message}"
  debug "GitInfo: \t#{self.sha}"
  debug "GitInfo: \t#{self.repo_internal_path}"
  debug "GitInfo: \t#{self.repo}"
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/lolcommits/git_info.rb', line 5

def message
  @message
end

#repoObject

Returns the value of attribute repo.



5
6
7
# File 'lib/lolcommits/git_info.rb', line 5

def repo
  @repo
end

#repo_internal_pathObject

Returns the value of attribute repo_internal_path.



5
6
7
# File 'lib/lolcommits/git_info.rb', line 5

def repo_internal_path
  @repo_internal_path
end

#shaObject

Returns the value of attribute sha.



5
6
7
# File 'lib/lolcommits/git_info.rb', line 5

def sha
  @sha
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/lolcommits/git_info.rb', line 5

def url
  @url
end

Instance Method Details

#remote_https_url(url) ⇒ Object



7
8
9
# File 'lib/lolcommits/git_info.rb', line 7

def remote_https_url(url)
  url.gsub(':', '/').gsub(/^git@/, 'https://').gsub(/\.git$/, '') + '/commit/'
end