Skip to content

Instantly share code, notes, and snippets.

@msmithstubbs
Created March 3, 2011 19:01
Show Gist options
  • Save msmithstubbs/853288 to your computer and use it in GitHub Desktop.
Save msmithstubbs/853288 to your computer and use it in GitHub Desktop.
#
# Quick script to migrate issues from Pivotal Tracker to GitHub
#
# Based on https://github.com/suitmymind/lighthouse-to-github/blob/master/migrate-lh-to-gh.rb
# and pivotal-tracker gem: https://github.com/jsmestad/pivotal-tracker
#
#
require 'pivotal-tracker'
require 'yaml'
GITHUB_LOGIN = "your_username"
GITHUB_API_TOKEN = "your_token"
GITHUB_PROJECT = "Your-Project-Name"
GITHUB_NEW_ISSUE_API_URL = "https://github.com/api/v2/yaml/issues/open/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}"
GITHUB_CLOSE_ISSUE_API_URL = "https://github.com/api/v2/yaml/issues/close/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}"
GITHUB_ADD_COMMENT_API_URL = "https://github.com/api/v2/yaml/issues/comment/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}"
GITHUB_ADD_LABEL_API_URL = "https://github.com/api/v2/yaml/issues/label/add/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}"
PivotalTracker::Client.token('you@example.com', 'your_password')
@a_project = PivotalTracker::Project.find(ARGV[0]) # specify the project ID as the first argument
@a_project.stories.all.each do |story|
next if story.story_type == 'release'
puts "#{story.name}: #{story.story_type}"
title = story.name
body = story.description || ""
# escape single quote
body.gsub!(/'/,"’")
gh_return_value = `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F "title=#{title}" -F 'body=#{body}' #{GITHUB_NEW_ISSUE_API_URL}`
gh_issue_id = YAML::load(gh_return_value)["issue"]["number"]
if story.current_state == 'accepted' # mark this one as closed
gh_return_value = `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_CLOSE_ISSUE_API_URL}/#{gh_issue_id}`
end
if story.story_type == 'chore'
gh_return_value = `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/Chore/#{gh_issue_id}`
end
if story.story_type == 'feature'
gh_return_value = `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/Feature/#{gh_issue_id}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment