Sha256: 3739d0f2bafb2f942cfec5cac29c2be8d657363166646197239a28c590dcf76d

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require 'pivotal-github/command'

class StoryCommit < Command

  def parser
    OptionParser.new do |opts|
      opts.banner = "Usage: git story-commit [options]"
      opts.on("-m", "--message MESSAGE",
              "add a commit message (including story #)") do |opt|
        self.options.message = opt
      end
      opts.on("-f", "--finish", "mark story as finished") do |opt|
        self.options.finish = opt
      end
      opts.on("-d", "--deliver", "mark story as delivered") do |opt|
        self.options.deliver = opt
      end
      opts.on("-a", "--all", "commit all changed files") do |opt|
        self.options.all = opt
      end
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  def message
    if story_ids.empty?
      # Arranges to fall through to regular 'git commit'
      options.message
    else
      if finish?
        label = "Finishes #{message_ids}"
      elsif deliver?
        label = "Delivers #{message_ids}"
      else
        label = message_ids
      end
      "[#{label}] #{options.message}"
    end
  end

  # Returns the story ids formatted for story commits.
  # For single-id stories, this is just the number preceded by '#', as in
  # '#6283185'. For multiple-id stories, each story id is precede by '#', as in
  # '#6283185 #3141592'
  def message_ids
    story_ids.map { |id| "##{id}" }.join(' ')
  end

  # Returns a command appropriate for executing at the command line.
  # We take care to insert the story number and, if necessary, an indication
  # that the commit finishes the story.
  def cmd
    c = ['git commit']
    c << '-a' if all?
    c << %(-m "#{message}") if message?
    c << argument_string(unknown_options) unless unknown_options.empty?
    c.join(' ')
  end

  def run!
    system cmd
  end

  private

    def finish?
      options.finish
    end

    def deliver?
      options.deliver
    end

    def message?
      !options.message.nil?
    end

    def all?
      options.all
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pivotal-github-0.7.0 lib/pivotal-github/story_commit.rb