Created
November 24, 2009 16:23
-
-
Save inkdeep/241990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'highline' | |
require 'xmlsimple' | |
# Retrieves stories a user owns from PivotalTracker API | |
# Formats the name and story number for pivotial friendly commit messages. | |
# | |
# Add this to .bash_profile or .bashrc and replace the values with your information: | |
# ## pivotal tracker API call variables | |
# export PT_API_KEY='_YOUR_API_KEY_' | |
# export PT_PROJECT_KEY='_PROJECT_NUMBER_' | |
# export PT_STORY_OWNER='_YOUR_NAME_' | |
# | |
# Put a string as an argument when calling the script to prepend text to the story name - default string is 'www' | |
# $ ptstory enet | |
# $ ptstory 'I like cheese' | |
class PtStory | |
def initialize | |
@argv = !$*.empty? ? $* : 'www' | |
@ids_titles = [] | |
@formatted = [] | |
get_pt_stories | |
end | |
def ui | |
@ui ||= HighLine.new | |
end | |
def get_pt_stories | |
stories = XmlSimple.xml_in(`curl -s -H "X-TrackerToken: #{ENV['PT_API_KEY']}" -X GET http://www.pivotaltracker.com/services/v2/projects/#{ENV['PT_PROJECT_KEY']}/stories?filter=owner%3A%22#{URI.escape(ENV['PT_STORY_OWNER'])}%22`) | |
if stories.is_a?(Hash) | |
stories['story'].each {|s| @ids_titles << [s['id'][0]['content'], s['name']] } | |
@ids_titles.each_index {|x| @formatted << "[##{@ids_titles[x][0]}] #{@argv} - #{@ids_titles[x][1]}"} | |
puts '-' * 80 | |
@formatted.each_index {|x| puts "#{x.to_s.rjust(2)}: #{@formatted[x]}"} | |
puts '-' * 80 | |
elsif stories.is_a?(String) | |
raise "API ERROR: #{stories}" | |
else | |
raise "Something is very wrong…" | |
end | |
end | |
def which_one | |
choice = '' | |
loop do | |
prompt = "Enter number of story commit message to copy to clipboard:" | |
choice = ui.ask(prompt) | |
if /^\d+$/ =~ choice.to_s && choice.to_i <= @formatted.length-1 | |
`echo #{@formatted[choice.to_i]} | pbcopy` | |
puts "Copied to clipboard: \e[1;36m#{@formatted[choice.to_i ]}\e[0m" | |
return true | |
else | |
$stderr.puts ">>>try again<<<" | |
end | |
end | |
end | |
end | |
stories = PtStory.new | |
stories.which_one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment