-
-
Save robotarmy/2257596 to your computer and use it in GitHub Desktop.
hacky script to import pivotal tracker csv into github issues
This file contains 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
#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 |
This file contains 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
#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 |
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
worked great for me, thank you for providing!