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

Support for tasks #11

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 4 additions & 1 deletion bin/slurp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
21 changes: 20 additions & 1 deletion lib/slurper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
require 'yaml'
require 'logger'
require 'active_resource'
require 'story'
require 'task'
YAML::ENGINE.yamler='syck' if RUBY_VERSION > '1.9'


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
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions lib/story.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'active_resource'

class Story < ActiveResource::Base

def self.yaml
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions lib/task.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/fixtures/story_with_tasks.slurper
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/slurper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 34 additions & 10 deletions spec/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
62 changes: 62 additions & 0 deletions spec/task_spec.rb
Original file line number Diff line number Diff line change
@@ -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