Class: Lolcommits::GitInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/backends/git_info.rb

Constant Summary collapse

GIT_URL_REGEX =
%r{.*[:]([\/\w\-]*).git}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitInfo

Returns a new instance of GitInfo.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lolcommits/backends/git_info.rb', line 13

def initialize
  debug 'GitInfo: parsed the following values from commit:'
  debug "GitInfo: \t#{message}"
  debug "GitInfo: \t#{sha}"
  debug "GitInfo: \t#{repo_internal_path}"
  debug "GitInfo: \t#{repo}"
  debug "GitInfo: \t#{branch}"
  debug "GitInfo: \t#{commit_date}"
  debug "GitInfo: \t#{author_name}" if author_name
  debug "GitInfo: \t#{author_email}" if author_email
end

Class Method Details

.local_name(path = '.') ⇒ Object



9
10
11
# File 'lib/lolcommits/backends/git_info.rb', line 9

def self.local_name(path = '.')
  File.basename(Git.open(path).dir.to_s)
end

.repo_root?(path = '.') ⇒ Boolean

Returns:

  • (Boolean)


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

def self.repo_root?(path = '.')
  File.directory?(File.join(path, '.git'))
end

Instance Method Details

#author_emailObject



70
71
72
# File 'lib/lolcommits/backends/git_info.rb', line 70

def author_email
  @author_email ||= last_commit.author.email if last_commit.author
end

#author_nameObject



66
67
68
# File 'lib/lolcommits/backends/git_info.rb', line 66

def author_name
  @author_name ||= last_commit.author.name if last_commit.author
end

#branchObject



25
26
27
# File 'lib/lolcommits/backends/git_info.rb', line 25

def branch
  @branch ||= repository.current_branch
end

#commit_dateObject



74
75
76
# File 'lib/lolcommits/backends/git_info.rb', line 74

def commit_date
  @commit_date ||= last_commit.date.utc
end

#messageObject



29
30
31
32
33
34
# File 'lib/lolcommits/backends/git_info.rb', line 29

def message
  @message ||= begin
    message = last_commit.message || ''
    message.split("\n").first
  end
end

#repoObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lolcommits/backends/git_info.rb', line 52

def repo
  @repo ||= begin
    if repository.remote && repository.remote.url
      match = repository.remote.url.match(GIT_URL_REGEX)
    end

    if match
      match[1]
    elsif !repository.repo.path.empty?
      repository.repo.path.split(File::SEPARATOR)[-2]
    end
  end
end

#repo_internal_pathObject



40
41
42
# File 'lib/lolcommits/backends/git_info.rb', line 40

def repo_internal_path
  @repo_internal_path ||= repository.repo.path
end

#shaObject



36
37
38
# File 'lib/lolcommits/backends/git_info.rb', line 36

def sha
  @sha ||= last_commit.sha[0..10]
end

#urlObject



44
45
46
47
48
49
50
# File 'lib/lolcommits/backends/git_info.rb', line 44

def url
  @url ||= begin
    if repository.remote && repository.remote.url
      remote_https_url(repository.remote.url)
    end
  end
end