Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #39 to allow for a story id to be specified for the pick commands ... #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down
17 changes: 13 additions & 4 deletions lib/commands/pick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions spec/commands/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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