Class: Peek::Views::Git

Inherits:
View
  • Object
show all
Defined in:
lib/peek/views/git.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Git

A view to get some insight into the current state of git for your project. It gives you the sha, branch, and compare url.

nwo - The repository (name with owner). default_branch - master may not be your default branch. branch_name - The current branch name (Optional). sha - The current SHA for git (Optional). domain - Domain name of the location of the repository (Default: github.com). protocol - The protocol to use in the compare_url (Default: https).

Returns Peek::Views::Git



16
17
18
19
20
21
22
23
# File 'lib/peek/views/git.rb', line 16

def initialize(options = {})
  @nwo = options.delete(:nwo)
  @default_branch = options.fetch(:default_branch, 'master')
  @branch_name = options.delete(:branch_name)
  @sha = options.delete(:sha)
  @domain = options.fetch(:domain, 'github.com')
  @protocol = options.fetch(:protocol, 'https')
end

Instance Method Details

#branch_nameObject

Fetch the current branch name.



30
31
32
# File 'lib/peek/views/git.rb', line 30

def branch_name
  @branch_name ||= ENV['GIT_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.chomp
end

#compare_urlObject



43
44
45
# File 'lib/peek/views/git.rb', line 43

def compare_url
  "#{@protocol}://#{@domain}/#{@nwo}/compare/#{@default_branch}...#{sha}"
end

#nwo?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/peek/views/git.rb', line 25

def nwo?
  !!@nwo
end

#shaObject

Fetch the current sha if one isn’t present.



35
36
37
# File 'lib/peek/views/git.rb', line 35

def sha
  @sha ||= ENV['GIT_SHA'] || `git rev-parse HEAD`.chomp
end

#short_shaObject



39
40
41
# File 'lib/peek/views/git.rb', line 39

def short_sha
  sha[0..6]
end