Class: Cp8Cli::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/cp8_cli/branch.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.currentObject



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

#checkoutObject



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_ciObject



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(options = {})
  pr = PullRequest.new options.merge(story: current_story, from: name, target: target)
  pr.open
end

#open_story_in_browserObject



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

#pushObject



25
26
27
# File 'lib/cp8_cli/branch.rb', line 25

def push
  Command.run "git push origin #{name} -u"
end

#targetObject



46
47
48
# File 'lib/cp8_cli/branch.rb', line 46

def target
  name_parts[2] || name
end