class Lolcommits::GitInfo
Constants
- GIT_URL_REGEX
Public Class Methods
local_name(path = '.')
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 11 def self.local_name(path = '.') File.basename(Git.open(path).dir.to_s) end
new()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 15 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
repo_root?(path = '.')
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 7 def self.repo_root?(path = '.') File.directory?(File.join(path, '.git')) end
Public Instance Methods
branch()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 27 def branch @branch ||= repository.current_branch end
commit_date()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 70 def commit_date @commit_date ||= last_commit.date.utc end
message()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 31 def message @message ||= begin message = last_commit.message || '' message.split("\n").first end end
repo()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 50 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_path()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 42 def repo_internal_path @repo_internal_path ||= repository.repo.path end
sha()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 38 def sha @sha ||= last_commit.sha[0..10] end
url()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 46 def url @url ||= remote_repo? ? remote_https_url(repository.remote&.url) : nil end
Private Instance Methods
debug(message)
click to toggle source
Calls superclass method
# File lib/lolcommits/backends/git_info.rb, line 76 def debug(message) super("#{self.class}: #{message}") end
last_commit()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 88 def last_commit @last_commit ||= repository.log.first end
remote_https_url(url)
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 80 def remote_https_url(url) "#{url.tr(':', '/').gsub(/^git@/, 'https://').gsub(/\.git$/, '')}/commit/" end
remote_repo?()
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 92 def remote_repo? !repository.remote&.url.nil? end
repository(path = '.')
click to toggle source
# File lib/lolcommits/backends/git_info.rb, line 84 def repository(path = '.') @repository ||= Git.open(path) end