class Cp8Cli::Branch
Attributes
name[R]
Public Class Methods
current()
click to toggle source
# File lib/cp8_cli/branch.rb, line 18 def self.current new Command.read("git rev-parse --abbrev-ref HEAD") end
new(name)
click to toggle source
# File lib/cp8_cli/branch.rb, line 14 def initialize(name) @name = name end
suggestion()
click to toggle source
# File lib/cp8_cli/branch.rb, line 22 def self.suggestion new("suggestion-#{SecureRandom.hex(8)}") end
Public Instance Methods
checkout()
click to toggle source
# File lib/cp8_cli/branch.rb, line 26 def checkout Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}", title: "Checking out new branch" end
open_ci()
click to toggle source
# File lib/cp8_cli/branch.rb, line 38 def open_ci Ci.new(branch_name: name, repo: repo).open end
open_pr()
click to toggle source
# File lib/cp8_cli/branch.rb, line 34 def open_pr pull_request.open end
push()
click to toggle source
# File lib/cp8_cli/branch.rb, line 30 def push Command.run "git push origin #{name} -u", title: "Pushing to origin" end
reset()
click to toggle source
# File lib/cp8_cli/branch.rb, line 42 def reset if dirty? Command.error "Dirty working directory, not resetting." else Command.run "git reset --hard origin/#{name}", title: "Resetting branch" end end
to_s()
click to toggle source
# File lib/cp8_cli/branch.rb, line 50 def to_s name end
Private Instance Methods
dirty?()
click to toggle source
# File lib/cp8_cli/branch.rb, line 60 def dirty? Command.read("git status --porcelain") end
existing_pull_request()
click to toggle source
# File lib/cp8_cli/branch.rb, line 68 def existing_pull_request Github::PullRequest.find_by(branch: name, repo: repo) end
new_pull_request()
click to toggle source
# File lib/cp8_cli/branch.rb, line 72 def new_pull_request Github::PullRequest.new(from: name) end
pull_request()
click to toggle source
# File lib/cp8_cli/branch.rb, line 64 def pull_request existing_pull_request || new_pull_request end
repo()
click to toggle source
# File lib/cp8_cli/branch.rb, line 56 def repo Repo.current end