Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for tasks #11

Closed
wants to merge 2 commits into from

2 participants

@archfear

I modified slurper to support import stories with tasks.

Cheers,
Dan

@adamlowe

Oops. Just saw this Dan. Apologies for the delay. Will have a look this week.

@adamlowe

Did you build, install and smoke test this?

@adamlowe adamlowe closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  README.rdoc
@@ -63,6 +63,9 @@ Or even
Set Up Staging Environment
description:
Set up and configure staging environment for approval of stories
+ tasks:
+ - set up staging db server
+ - set up staging app server
labels:
View
5 bin/slurp
@@ -22,8 +22,11 @@ OptionParser.new do |opts|
opts.on("-r", "--reverse", "Reverse story creation order") do |v|
options[:reverse] = v
end
+ opts.on("-d", "--debug", "Display detailed network request info") do |d|
+ options[:debug] = d
+ end
end.parse!
story_file = ARGV.empty? ? "stories.slurper" : ARGV[0]
-Slurper.slurp(story_file, options[:reverse])
+Slurper.slurp(story_file, options[:reverse], options[:debug])
View
21 lib/slurper.rb
@@ -1,5 +1,8 @@
require 'yaml'
+require 'logger'
+require 'active_resource'
require 'story'
+require 'task'
YAML::ENGINE.yamler='syck' if RUBY_VERSION > '1.9'
@@ -7,7 +10,14 @@ class Slurper
attr_accessor :story_file, :stories
- def self.slurp(story_file, reverse)
+ def self.slurp(story_file, reverse, debug=false)
+ if debug
+ ActiveResource::Base.logger = Logger.new(STDOUT)
+ ActiveResource::Base.logger.level = Logger::DEBUG
+ else
+ ActiveResource::Base.logger = nil
+ end
+
slurper = new(story_file)
slurper.load_stories
slurper.prepare_stories
@@ -31,8 +41,17 @@ def create_stories
puts "Preparing to slurp #{stories.size} stories into Tracker..."
stories.each_with_index do |story, index|
begin
+ tasks = story.extract_tasks
if story.save
puts "#{index+1}. #{story.name}"
+ tasks.each do |task|
+ task.prefix_options[:story_id] = story.id
+ if task.save
+ puts "- #{task.description}"
+ else
+ puts "Slurp failed. #{task.errors.full_messages}"
+ end
+ end
else
puts "Slurp failed. #{story.errors.full_messages}"
end
View
16 lib/story.rb
@@ -1,5 +1,3 @@
-require 'active_resource'
-
class Story < ActiveResource::Base
def self.yaml
@@ -27,6 +25,20 @@ def prepare
default_requested_by
end
+ def to_xml(options={})
+ options[:except] ||= []
+ options[:except] << :tasks
+ super(options)
+ end
+
+ def extract_tasks
+ if respond_to?(:tasks)
+ tasks.collect {|task| Task.new(:description => task)}
+ else
+ []
+ end
+ end
+
protected
def scrub_description
View
36 lib/task.rb
@@ -0,0 +1,36 @@
+class Task < ActiveResource::Base
+
+ def self.yaml
+ YAML.load_file('slurper_config.yml')
+ end
+
+ def self.config
+ @@config = yaml
+ scheme = if !!@@config['ssl']
+ self.ssl_options = { :verify_mode => OpenSSL::SSL::VERIFY_PEER,
+ :ca_file => File.join(File.dirname(__FILE__), "cacert.pem") }
+ "https"
+ else
+ "http"
+ end
+ self.site = "#{scheme}://www.pivotaltracker.com/services/v3/projects/#{@@config['project_id']}/stories/:story_id"
+ @@config
+ end
+
+
+ headers['X-TrackerToken'] = config.delete("token")
+
+ def prepare
+ scrub_description
+ end
+
+ protected
+
+ def scrub_description
+ if respond_to?(:description)
+ self.description = description.gsub(" ", "")
+ self.attributes["description"] = nil if description == ""
+ end
+ end
+
+end
View
14 spec/fixtures/story_with_tasks.slurper
@@ -0,0 +1,14 @@
+==
+story_type:
+ feature
+name:
+ Profit
+description:
+ In order to do something
+ As a role
+ I want to click a thingy
+tasks:
+- do the thing
+- don't forget the other thing
+labels:
+ money,power,fame
View
12 spec/slurper_spec.rb
@@ -65,4 +65,16 @@
end
end
+ context "with tasks" do
+ before do
+ slurper = Slurper.new(File.join(File.dirname(__FILE__), "fixtures", "story_with_tasks.slurper"))
+ slurper.load_stories
+ @story = slurper.stories.first
+ end
+
+ it "parses the tasks correctly" do
+ @story.tasks.should == ["do the thing", "don't forget the other thing"]
+ end
+ end
+
end
View
44 spec/story_spec.rb
@@ -4,6 +4,21 @@
describe Story do
+ it "uses http by default" do
+ Story.site.scheme.should == "http"
+ Story.yaml['ssl'].should be_nil
+ end
+
+ it "uses https if set in the config" do
+ Story.stub(:yaml => {"ssl" => true})
+ Story.config['ssl'].should be_true
+ Story.site.scheme.should == "https"
+ Story.ssl_options[:verify_mode].should == 1
+
+ # Not sure what this next line is testing
+ File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ end
+
context "#prepare" do
it "scrubs the description" do
story = Story.new
@@ -18,20 +33,29 @@
story.should_receive(:default_requested_by)
story.prepare
end
+ end
- it "uses http by default" do
- Story.site.scheme.should == "http"
- Story.yaml['ssl'].should be_nil
+ context "#to_xml" do
+ it "excludes the tasks attribute" do
+ story = Story.new(
+ :story_type => "feature",
+ :name => "Profit",
+ :tasks => ["build something epic", "charge a lot for it"])
+ story.to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<story>\n <story-type>feature</story-type>\n <name>Profit</name>\n</story>\n"
end
+ end
- it "uses https if set in the config" do
- Story.stub(:yaml => {"ssl" => true})
- Story.config['ssl'].should be_true
- Story.site.scheme.should == "https"
- Story.ssl_options[:verify_mode].should == 1
+ context "#extract_tasks" do
+ it "returns an empty array for a story with no tasks" do
+ story = Story.new
+ story.extract_tasks.should == []
+ end
- # Not sure what this next line is testing
- File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ it "returns an array of Tasks with the appropriate descriptions for a story with tasks" do
+ story = Story.new(:tasks => ["build something epic"])
+ task = story.extract_tasks[0]
+ task.should be_an_instance_of(Task)
+ task.description.should == "build something epic"
end
end
View
62 spec/task_spec.rb
@@ -0,0 +1,62 @@
+require 'rubygems'
+require 'spec'
+require 'slurper'
+
+describe Task do
+
+ it "uses http by default" do
+ Task.site.scheme.should == "http"
+ Task.yaml['ssl'].should be_nil
+ end
+
+ it "uses https if set in the config" do
+ Task.stub(:yaml => {"ssl" => true})
+ Task.config['ssl'].should be_true
+ Task.site.scheme.should == "https"
+ Task.ssl_options[:verify_mode].should == 1
+
+ # Not sure what this next line is testing
+ File.open(File.expand_path('lib/cacert.pem')).readlines.find_all{ |l| l.starts_with?("Equifax") }.count.should == 4
+ end
+
+ context "#prepare" do
+ it "scrubs the description" do
+ task = Task.new
+ task.stub!(:default_requested_by)
+ task.should_receive(:scrub_description)
+ task.prepare
+ end
+ end
+
+ context "scrubs the descriptions correctly" do
+ it "when the description is blank" do
+ task = Task.new(:description => "")
+ task.send(:scrub_description)
+ task.description.should be_nil
+ end
+
+ it "when there is no description given" do
+ task = Task.new
+ lambda {
+ task.send(:scrub_description)
+ }.should_not raise_error
+ end
+
+ it "when it contains quotes" do
+ desc = <<-STRING
+ I have a "quote"
+ STRING
+ task = Task.new(:description => desc)
+ task.send(:scrub_description)
+ task.description.should == "I have a \"quote\"\n"
+ end
+
+ it "when it is full of whitespace" do
+ desc = " Do this task "
+ task = Task.new(:description => desc)
+ task.send(:scrub_description)
+ task.description.should == "Do this task"
+ end
+ end
+
+end
Something went wrong with that request. Please try again.