Sha256: 920d071e9fde47d3ca52df2f70e60484774b48f6e88df868c22a2d02a83c5aa1

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 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 |m|
        self.options.message = m
      end
      opts.on("-f", "--finish", "mark story as finished") do |f|
        self.options.finish = f
      end
      opts.on("-d", "--deliver", "mark story as delivered") do |d|
        self.options.deliver = d
      end
      opts.on("-a", "--all", "commit all changed files") do |a|
        self.options.all = a
      end
      opts.on_tail("-h", "--help", "this usage guide") do
        puts opts.to_s; exit 0
      end
    end
  end

  def message
    if story_id.nil?
      # Arranges to fall through to regular 'git commit'
      options.message
    else
      if finish?
        label = "Finishes ##{story_id}"
      elsif deliver?
        label = "Delivers ##{story_id}"
      else
        label = "##{story_id}"
      end
      "[#{label}] #{options.message}"
    end
  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

18 entries across 18 versions & 1 rubygems

Version Path
pivotal-github-0.6.12 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.11 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.10 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.9 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.8 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.7 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.6 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.5 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.4 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.3 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.2 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.1 lib/pivotal-github/story_commit.rb
pivotal-github-0.6.0 lib/pivotal-github/story_commit.rb
pivotal-github-0.5.6 lib/pivotal-github/story_commit.rb
pivotal-github-0.5.5 lib/pivotal-github/story_commit.rb
pivotal-github-0.5.4 lib/pivotal-github/story_commit.rb
pivotal-github-0.5.3 lib/pivotal-github/story_commit.rb
pivotal-github-0.5.2 lib/pivotal-github/story_commit.rb