class BBFlow::Application

Public Class Methods

run(command) click to toggle source

@param [Symbol] command

@return [void]

# File lib/bb_flow.rb, line 30
def self.run(command)
  case command
  when :commit
    return puts Misc.execute('git commit') if Misc.execute('git diff-index HEAD --name-only --cached').empty?

    message = (Options.get(:commit_message) || Misc.edit).strip
    cards = Trello.cards
    cards = Printer.select_items(cards, 'Which cards does this commit address?', formatter: Trello.method(:format_card)) unless cards.blank?
    card_lines = cards.map do |card|
      "Trello Card: #{card.name}, #{card.short_url}"
    end.join("\n")
    # TODO: re-write with plumbing commands
    # e.g. git write-tree | xargs git commit-tree -m'message'
    Misc.execute("git commit -m \"#{message}\n\n#{card_lines}\"")
    commit_sha = Misc.execute('git show-ref --head -s /HEAD/').strip
    # TODO: convert to http url.
    commit_url = "#{Github.http_url}/commit/#{commit_sha}"

    cards.each do |card|
      card.add_attachment(commit_url, message)
      Printer.success("Added the commit to the „#{card.name}“ card (#{card.url}).")
    end
  when :pr
    PullRequester.create!
  else
    Printer.panic("Incorrect parameter: #{command}")
  end
end