Skip to content

Instantly share code, notes, and snippets.

@harmaty
Created January 16, 2013 17:30
Show Gist options
  • Save harmaty/4549001 to your computer and use it in GitHub Desktop.
Save harmaty/4549001 to your computer and use it in GitHub Desktop.
This script imports issues from Planbox csv file to Github.
require "net/http"
require "uri"
require "json"
require "csv"
class TicketsImport
def initialize(options)
@uri = URI.parse("https://api.github.com/repos/#{options[:user]}/#{options[:repo]}/issues")
@http = Net::HTTP.new(@uri.host, @uri.port)
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@login = options[:login]
@password = options[:password]
end
def create_issue options = {}
request = Net::HTTP::Post.new(@uri.request_uri)
request.basic_auth @login, @password
request.body = options.to_json
response = @http.request(request)
end
def run params
puts " #{params[:filename]}"
items = Items.new(params[:filename]).all
items.each do |number, item|
puts item[:title]
options = {
title: item[:title],
body: item[:body],
assignee: params[:assignee],
milestone: params[:milestone]
}
options.merge!(labels: params[:labels]) if params[:labels]
create_issue options
end
end
end
class Items
def initialize(filename)
@filename = filename
end
def all
csv = CSV.read(@filename)
csv.shift
items = {}
csv.each do |row|
if items[row[0]].nil?
items[row[0]] = {}
end
if items[row[0]][:title].nil?
items[row[0]][:title] = row[3]
end
if items[row[0]][:body].nil?
items[row[0]][:body] = row[7]
else
items[row[0]][:body] << "\n______________\n" + row[7]
end
end
items
end
end
# Usage
import = TicketsImport.new(user: 'vasya', repo: 'monrepo', login: 'harmaty', password: '*****')
import.run filename: 'backlog.csv', assignee: 'oleg', milestone: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment