Sha256: 133411b8d5f02f994244a979dd324d13010108739a87de967a2f48fb6016d32e

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require "active_support/core_ext/string/inflections"
require "trello_flow/pull_request"

module TrelloFlow
  class Branch
    def initialize(name)
      @name = name
    end

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

    def self.from_item(item)
      new("#{current.target}.#{item.to_param}.#{item.checklist_id}-#{item.id}")
    end

    def checkout
      Cli.run "git checkout #{name} || git checkout -b #{name}"
    end

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

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

    def complete_current_item
      current_item.complete
    end

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

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

    private

      attr_reader :name

      def ids
        name.split(".").last.split("-")
      end

      def checklist_id
        ids.first
      end

      def item_id
        ids.last if ids.size == 2
      end

      def current_item
        @_current_item ||= Api::Item.find(checklist_id, item_id) if item_id
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trello_flow-1.3.0 lib/trello_flow/branch.rb