Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script that allows you to take a pivotal URL and make it a Things task
## Argument usage:
## ruby pivotalthings [url] [p/t] [beta]
## url = path to pivotal ticket
## p = make a project
## t = make only a todo
## beta = add beta to the end of the command line to use Things beta if installed
require "appscript"
include Appscript
require "Curb"
require "xmlsimple"
pt_token = File.open("pt_token.txt").readline ## pivotal user token, see https://www.pivotaltracker.com/help/api?version=v3#retrieve_token
pt_project = '168859' ## Project name
things_area = 'Work @ SoundCloud' # name of the area you want to put tasks in when they're not projects
pt_story = ARGV[0].match(/story\/show\/([0-9]{8,11})/)[1]
if ARGV[2] == "beta"
things = "Things beta"
else
things = "Things"
end
url = "https://www.pivotaltracker.com/services/v3/projects/#{pt_project}/stories/#{pt_story}"
curl = Curl::Easy.new(url)
curl.headers["X-TrackerToken"] = pt_token
curl.perform
if ARGV[1] == "p" && curl.body_str
story = XmlSimple.xml_in(curl.body_str)
app(things).make(
:new => :project,
:with_properties =>
{
:name => story['name'],
:notes => "#{story['url'].join}\n\n#{story['description'].join}"
}
)
unless story['tasks'].count == 0
story['tasks'].first['task'].each do |task|
app(things).
projects[story['name'].join].make(
:new => :to_do,
:with_properties => { :name => task['description'] }
)
end
end
elsif curl.body_str && things_area != ""
story = XmlSimple.xml_in(curl.body_str)
app(things).areas[things_area].make(:new => :to_do, :with_properties => {:name => story['name'], :notes => "#{story['url'].join}\n\n#{story['description'].join}"})
else
story = XmlSimple.xml_in(curl.body_str)
app(things).make(:new => :to_do, :with_properties => {:name => story['name'], :notes => "#{story['url'].join}\n\n#{story['description'].join}"})
end
if curl.body_str && things_area != ""
elsif curl.body_str
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment