Class: Cp8Cli::Branch
- Inherits:
-
Object
- Object
- Cp8Cli::Branch
- Defined in:
- lib/cp8_cli/branch.rb
Class Method Summary collapse
Instance Method Summary collapse
- #checkout ⇒ Object
-
#initialize(name) ⇒ Branch
constructor
A new instance of Branch.
- #open_ci ⇒ Object
- #open_pull_request(options = {}) ⇒ Object
- #open_story_in_browser ⇒ Object
- #push ⇒ Object
- #target ⇒ Object
Constructor Details
#initialize(name) ⇒ Branch
Returns a new instance of Branch.
9 10 11 |
# File 'lib/cp8_cli/branch.rb', line 9 def initialize(name) @name = name end |
Class Method Details
.current ⇒ Object
13 14 15 |
# File 'lib/cp8_cli/branch.rb', line 13 def self.current new Command.read("git rev-parse --abbrev-ref HEAD") end |
.from_story(user:, story:) ⇒ Object
17 18 19 |
# File 'lib/cp8_cli/branch.rb', line 17 def self.from_story(user:, story:) new BranchName.new(user: user, target: current.target, story: story).to_s end |
Instance Method Details
#checkout ⇒ Object
21 22 23 |
# File 'lib/cp8_cli/branch.rb', line 21 def checkout Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}" end |
#open_ci ⇒ Object
34 35 36 |
# File 'lib/cp8_cli/branch.rb', line 34 def open_ci Ci.new(branch_name: name, repo: Repo.current).open end |
#open_pull_request(options = {}) ⇒ Object
29 30 31 32 |
# File 'lib/cp8_cli/branch.rb', line 29 def open_pull_request( = {}) pr = PullRequest.new .merge(story: current_story, from: name, target: target) pr.open end |
#open_story_in_browser ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/cp8_cli/branch.rb', line 38 def open_story_in_browser if current_story Command.open_url current_story.url else Command.error "Not currently on story branch" end end |
#push ⇒ Object
25 26 27 |
# File 'lib/cp8_cli/branch.rb', line 25 def push Command.run "git push origin #{name} -u" end |
#target ⇒ Object
46 47 48 |
# File 'lib/cp8_cli/branch.rb', line 46 def target name_parts[2] || name end |