From 6b33e79b06ec6748f4e026f3a6f29cce68b0fe39 Mon Sep 17 00:00:00 2001 From: Simon de Boer Date: Fri, 15 Nov 2013 16:40:55 -0500 Subject: [PATCH] Fixes #39 to allow for a story id to be specified for the pick commands (feature, bug, chore). Note that although there is nothing stating this, it ignores the only-mine restriction. --- lib/commands/base.rb | 8 ++++++-- lib/commands/pick.rb | 17 +++++++++++++---- spec/commands/base_spec.rb | 10 ++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/commands/base.rb b/lib/commands/base.rb index 9d9ee5f..36cbe6d 100644 --- a/lib/commands/base.rb +++ b/lib/commands/base.rb @@ -13,7 +13,11 @@ def initialize(input=STDIN, output=STDOUT, *args) @options = {} parse_gitconfig - parse_argv(*args) + remaining = parse_argv(*args) + + if remaining.one? + @options[:story_id] = remaining.first + end end def put(string, newline=true) @@ -78,7 +82,7 @@ def parse_gitconfig def parse_argv(*args) OptionParser.new do |opts| - opts.banner = "Usage: git pick [options]" + opts.banner = "Usage: git pick [options] [story_id]" opts.on("-k", "--api-key=", "Pivotal Tracker API key") { |k| options[:api_token] = k } opts.on("-p", "--project-id=", "Pivotal Trakcer project id") { |p| options[:project_id] = p } opts.on("-n", "--full-name=", "Pivotal Trakcer full name") { |n| options[:full_name] = n } diff --git a/lib/commands/pick.rb b/lib/commands/pick.rb index 769be49..14261fe 100755 --- a/lib/commands/pick.rb +++ b/lib/commands/pick.rb @@ -63,14 +63,23 @@ def run! end end - protected + protected def story return @story if @story - conditions = { :story_type => type, :current_state => "unstarted", :limit => 1, :offset => 0 } - conditions[:owned_by] = options[:full_name] if options[:only_mine] - @story = project.stories.all(conditions).first + @story = if options[:story_id] + project.stories.find options[:story_id] + else + conditions = { + :story_type => type, + :current_state => "unstarted", + :limit => 1, + :offset => 0 + } + conditions[:owned_by] = options[:full_name] if options[:only_mine] + project.stories.all(conditions).first + end end end end diff --git a/spec/commands/base_spec.rb b/spec/commands/base_spec.rb index fa60f03..f831b96 100644 --- a/spec/commands/base_spec.rb +++ b/spec/commands/base_spec.rb @@ -148,4 +148,14 @@ @pick.options[:use_ssl].should be_false end + it "should look up the specific story (by id) if it is given" do + @pick = Commands::Base.new(@input, @output, "54321") + @pick.options[:story_id].should == "54321" + end + + it "should default to no story id" do + @pick = Commands::Base.new(@input, @output, "") + @pick.options[:story_id].should be_null + end + end