casualjim
1/25/2011 - 8:21 AM

iterations.erb

#!/usr/bin/env ruby
require 'rubygems'
require 'active_resource'
require 'erb'

class Iteration < ActiveResource::Base
	self.site = "http://www.pivotaltracker.com/services/v3/projects/:project_id"
	self.proxy = ENV["HTTP_PROXY"] if ENV["HTTP_PROXY"]
	headers['X-TrackerToken'] = '1234567890acbdef1234567890acbdef'
end

PROJECT_ID = ARGV[0]
raise ArgumentError.new('Please specify project id (like "64534")') if PROJECT_ID.nil?

current_iteration = Iteration.find(:all, :params => {:project_id => PROJECT_ID, :group => "current"})
iterations_backlog = Iteration.find(:all, :params => {:project_id => PROJECT_ID, :group => "backlog"}) 

iterations = current_iteration + iterations_backlog

tpl = ERB.new(File.read( "#{File.expand_path(File.dirname($0))}/iterations.erb" ))

puts tpl.result
<% iterations.each do |iteration| %>
<h2 id='Sprint_<%= iteration.number %>' style='display:inline'>Sprint <%= iteration.number %></h2><i> - ends <%= iteration.finish.strftime("%Y-%m-%d") %></i><a href='#Sprint_<%= iteration.number %>' class='anchor'>&nbsp;&para;</a>
<ul>
	<% iteration.stories.each do |story| %>
	<li class='story'><h3 style='display:inline'><i>Story <%= story.id %> (<%= story.current_state %>)</i></h3>
		<small class='taskCount'><i><%= " - #{story.tasks.size} tasks defined" if story.respond_to?(:tasks) %></i></small>
		<p class='storyDescription'><span class="storyIngress"><%= story.name%></span><br><span class="storyRest" style="color:grey"></span></p>
	<% end %>
</ul>
<% end %>