class Octokom::Repository
Public Class Methods
new(verbose)
click to toggle source
# File lib/octokom/repository.rb, line 5 def initialize(verbose) @verbose = verbose end
Public Instance Methods
base_branch()
click to toggle source
TODO Make base branch configurable.
# File lib/octokom/repository.rb, line 20 def base_branch 'master' end
head_branch()
click to toggle source
# File lib/octokom/repository.rb, line 24 def head_branch git('rev-parse --abbrev-ref HEAD') end
last_commit_message()
click to toggle source
# File lib/octokom/repository.rb, line 36 def last_commit_message git('log -1 --oneline')[/^\w+\s(.*)$/, 1] end
pending_commits?()
click to toggle source
# 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)
click to toggle source
# File lib/octokom/repository.rb, line 40 def push(branch) git("push origin #{branch}") end
repo_path()
click to toggle source
# 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_path()
click to toggle source
# File lib/octokom/repository.rb, line 15 def toplevel_path git('rev-parse --show-toplevel') end
Private Instance Methods
git(cmd)
click to toggle source
# File lib/octokom/repository.rb, line 59 def git(cmd) puts "git #{cmd}" if verbose? `git #{cmd}`.chomp end
last_commits()
click to toggle source
# File lib/octokom/repository.rb, line 51 def last_commits @last_commits ||= git('branch -avvv') end
remote_url()
click to toggle source
TODO Make origin configurable.
# File lib/octokom/repository.rb, line 47 def remote_url @remote_url ||= git('config --get remote.origin.url') end
verbose?()
click to toggle source
# File lib/octokom/repository.rb, line 55 def verbose? !!@verbose end