Skip to content

Instantly share code, notes, and snippets.

@ayosec
Last active December 10, 2015 17:48
Show Gist options
  • Save ayosec/4469764 to your computer and use it in GitHub Desktop.
Save ayosec/4469764 to your computer and use it in GitHub Desktop.
Basic client to get PivotalTracker stories, in a easy to read format.

List for PivotalTracker stories

Get the stories for your PitalTracker project.

Installation

  • Install httparty and term-ansicolor gems
  • Download the pt-list.rb file in this gist.
  • Set execution flag with chmod +x
  • Put it in some directory in your $PATH

Configuration

Create a ~/.pivotal-tracker.conf with something like this:

token: "your-API-token"
project: 12345

The API token can be read from https://www.pivotaltracker.com/profile

#Screenshot

Click on the image to see the full size.

pt-list screenshot

#! /usr/bin/ruby
# gems: httpparty, term-ansicolor
require "rubygems"
require "yaml"
require "httparty"
require "term/ansicolor"
Conf = YAML::load_file(File.expand_path("~/.pivotal-tracker.conf"))
PROJECT = ENV["PT_PROJECT"] || Conf["project"]
class PTracker
include HTTParty
base_uri "https://www.pivotaltracker.com/services/v3"
headers "X-TrackerToken" => Conf["token"]
end
include Term::ANSIColor
def show_type(type)
color = {
"feature" => green,
"chore" => cyan,
"bug" => red,
"release" => negative
}[type]
type = "%-8s" % type
if color
color + type + reset
else
type
end
end
def show_state(state)
color = {
"unstarted" => yellow,
"rejected" => bold + white + on_red,
"accepted" => bold,
"started" => bold + white + on_magenta,
"finished" => green,
"delivered" => bold + white + on_green
}[state]
if color
color + state + reset + (" " * (12 - state.length))
else
"%-12s" % state
end
end
Format = " [#{blue}%s#{reset}] %s %s %-7s %-6s %s" # ID, type, state, owner, estimate, name
PTracker.get("/projects/#{PROJECT}/iterations/current_backlog")["iterations"].each do |iteration|
next if iteration["stories"].empty?
print bold,"Iteration #{iteration["number"]}", reset,
" (#{iteration["start"].strftime("%F")} - #{iteration["finish"].strftime("%F")})\n"
iteration["stories"].each do |story|
puts Format % [
story["id"],
show_type(story["story_type"]),
show_state(story["current_state"]),
story["owned_by"] ? story["owned_by"].split.first : "none",
story["estimate"] ? "#{story["estimate"]} pt." : "",
story["name"]
]
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment