Class: TrelloFlow::Branch

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Branch

Returns a new instance of Branch.



6
7
8
# File 'lib/trello_flow/branch.rb', line 6

def initialize(name)
  @name = name
end

Class Method Details

.currentObject



10
11
12
# File 'lib/trello_flow/branch.rb', line 10

def self.current
  new Cli.read("git rev-parse --abbrev-ref HEAD")
end

.from_card(card) ⇒ Object



14
15
16
# File 'lib/trello_flow/branch.rb', line 14

def self.from_card(card)
  new("#{current.target}.#{card.to_param}.#{card.id}")
end

Instance Method Details

#checkoutObject



18
19
20
# File 'lib/trello_flow/branch.rb', line 18

def checkout
  Cli.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}"
end

#finish_current_cardObject



30
31
32
# File 'lib/trello_flow/branch.rb', line 30

def finish_current_card
  current_card.finish
end

#open_pull_requestObject



26
27
28
# File 'lib/trello_flow/branch.rb', line 26

def open_pull_request
  PullRequest.new(current_card, from: name, target: target).open
end

#open_trello(user) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/trello_flow/branch.rb', line 34

def open_trello(user)
  if current_card
    Cli.open_url current_card.url
  else
    Cli.open_url "https://trello.com/#{user.username}/cards"
  end
end

#pushObject



22
23
24
# File 'lib/trello_flow/branch.rb', line 22

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

#targetObject



42
43
44
# File 'lib/trello_flow/branch.rb', line 42

def target
  name.split('.').first
end