Class: Octokom::Repository

Inherits:
Object show all
Includes:
Shell
Defined in:
lib/octokom/repository.rb

Instance Method Summary collapse

Methods included from Shell

#error, #info, #task

Constructor Details

#initialize(verbose) ⇒ Repository

Returns a new instance of Repository.



5
6
7
# File 'lib/octokom/repository.rb', line 5

def initialize(verbose)
  @verbose = verbose
end

Instance Method Details

#base_branchObject

TODO Make base branch configurable.



20
21
22
# File 'lib/octokom/repository.rb', line 20

def base_branch
  'master'
end

#head_branchObject



24
25
26
# File 'lib/octokom/repository.rb', line 24

def head_branch
  git('rev-parse --abbrev-ref HEAD')
end

#last_commit_messageObject



36
37
38
# File 'lib/octokom/repository.rb', line 36

def last_commit_message
  git('log -1 --oneline')[/^\w+\s(.*)$/, 1]
end

#pending_commits?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/octokom/repository.rb', line 28

def pending_commits?
  current_sha1 = last_commits[/^\*\s((\w|-|_)*)\s+(\w{7})/, 3]
  remote_sha1 = last_commits[/remotes\/origin\/#{head_branch}\s+(\w{7})/, 1]

  return true if remote_sha1.blank?
  current_sha1 != remote_sha1 ? true : false
end

#push(branch) ⇒ Object



40
41
42
# File 'lib/octokom/repository.rb', line 40

def push(branch)
  git("push origin #{branch}")
end

#repo_pathObject



9
10
11
12
13
# File 'lib/octokom/repository.rb', line 9

def repo_path
  error('Git remote not defined') if remote_url.blank?
  path = remote_url.split('/')[-2..-1]
  path.join('/')[/(.*)\.git$/, 1]
end

#toplevel_pathObject



15
16
17
# File 'lib/octokom/repository.rb', line 15

def toplevel_path
  git('rev-parse --show-toplevel')
end