Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacaetevha/11042884 to your computer and use it in GitHub Desktop.
Save jacaetevha/11042884 to your computer and use it in GitHub Desktop.
Pivotal Tracker Story Textalizer
#!/usr/bin/env ruby
require 'open-uri'
require "rexml/document"
TOKEN = ENV['TOKEN'] || '****'
PROJECT = ENV['PROJECT'] || '****'
STORY = ENV['STORY'] || ARGV[0]
# ripped from Rails
def word_wrap(text, line_width=40)
text.split("\n").collect! do |line|
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
xml = open("http://www.pivotaltracker.com/services/v3/projects/#{PROJECT}/stories/#{STORY}", "X-TrackerToken" => TOKEN)
doc = REXML::Document.new(xml).root
puts %q{*****************************************
*****************************************
}
puts word_wrap("#{STORY}: #{doc.elements.to_a('//story/name').first.text}")
puts
puts word_wrap(doc.elements.to_a("//story/description").first.text)
puts
count = 0
doc.elements.to_a('//story/tasks/task/description').each.with_index do |el, index|
text = el.text
if text =~ /DC\s*\d+\s*\[/
puts word_wrap(text)
else
puts word_wrap("DC#{index + 1} [ ] - #{text}")
end
end
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment