Skip to content

Instantly share code, notes, and snippets.

@robotarmy
Forked from visnup/import_issues.rb
Created March 30, 2012 23:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robotarmy/2257596 to your computer and use it in GitHub Desktop.
Save robotarmy/2257596 to your computer and use it in GitHub Desktop.
hacky script to import pivotal tracker csv into github issues
#encoding:UTF-8
#!/usr/bin/env ruby
require 'rubygems'
require 'FasterCSV'
require 'httparty'
require 'json'
require 'highline/import'
def get_input(prompt="Enter >",show = true)
ask(prompt) {|q| q.echo = show}
end
class GitHub
include HTTParty
base_uri 'https://api.github.com'
end
user = get_input("Enter Username >")
password = get_input("Enter Password >", "*")
GitHub.basic_auth user, password
labels = GitHub.get '/repos/robotarmy/driveless/labels'
labels.each do |label|
p GitHub.delete label['url'].split(GitHub.base_uri).last
end
#encoding:UTF-8
#!/usr/bin/env ruby
require 'rubygems'
require 'FasterCSV'
require 'httparty'
require 'json'
require 'highline/import'
def get_input(prompt="Enter >",show = true)
ask(prompt) {|q| q.echo = show}
end
filename = ARGV.shift or raise "Enter Filepath to CSV as ARG1"
class GitHub
include HTTParty
base_uri 'https://api.github.com'
end
user = get_input("Enter Username >")
password = get_input("Enter Password >", "*")
GitHub.basic_auth user, password
visited_labels = []
FasterCSV.open filename, :headers => true do |csv|
csv.each do |r|
body = {
:title => r['Story'],
:body => r['Description'],
}
labels = []
if r['Labels'] != ''
r['Labels'].split(',').each do |label|
label = label.strip
color =''
3.times {
color << "%02x" % rand(255)
}
unless visited_labels.include? label
labels << {:name => label, :color =>color}
end
end
labels.each do |label|
p label
# this hack doesn't care if you have an existing label - it just errors and moves on like a zen master
# the server however is expected to be equally zen :D
visited_labels << label[:name]
label = GitHub.post '/repos/robotarmy/driveless/labels', :body => JSON.generate(label)
p label
end
end
body[:labels] = r['Labels'].split(',').map {|l|l.strip} if r['Labels'] != ''
p json_body = JSON.generate(body)
issue = GitHub.post '/repos/robotarmy/driveless/issues', :body => json_body
p issue
r.each do |f|
if f[0] == 'Note'
next unless f[1]
body = { :body => f[1] }
GitHub.post "/repos/robotarmy/driveless/issues/#{issue.parsed_response['number']}/comments", :body => JSON.generate(body)
end
end
end
end
@robotarmy
Copy link
Author

no recreating labels - strip labels for whitespace..

@dwcaraway
Copy link

worked great for me, thank you for providing!

@antislice
Copy link

Didn't actually work for me, github probably changed something in their API. So I rewrote it to use their library: https://github.com/antislice/pivotal2github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment