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 "parsed the following values from commit:"
  debug "\t#{message}"
  debug "\t#{sha}"
  debug "\t#{repo_internal_path}"
  debug "\t#{repo}"
  debug "\t#{branch}"
  debug "\t#{commit_date}"
  debug "\t#{author_name}" if author_name
  debug "\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



64
65
66
# File 'lib/lolcommits/backends/git_info.rb', line 64

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

#author_nameObject



60
61
62
# File 'lib/lolcommits/backends/git_info.rb', line 60

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



68
69
70
# File 'lib/lolcommits/backends/git_info.rb', line 68

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



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lolcommits/backends/git_info.rb', line 48

def repo
  @repo ||= begin
    match = repository.remote.url.match(GIT_URL_REGEX) if remote_repo?

    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
# File 'lib/lolcommits/backends/git_info.rb', line 44

def url
  @url ||= remote_repo? ? remote_https_url(repository.remote&.url) : nil
end