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
  • Select an option

  • Save robotarmy/2257596 to your computer and use it in GitHub Desktop.

Select an option

Save robotarmy/2257596 to your computer and use it in GitHub Desktop.

Revisions

  1. robotarmy revised this gist Mar 31, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion import_issues.rb
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ class GitHub
    end
    end

    body[:labels] = r['Labels'].split(',') if r['Labels'] != ''
    body[:labels] = r['Labels'].split(',').map {|l|l.strip} if r['Labels'] != ''


    p json_body = JSON.generate(body)
  2. robotarmy revised this gist Mar 31, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion import_issues.rb
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,7 @@ class GitHub

    if r['Labels'] != ''
    r['Labels'].split(',').each do |label|
    label = label.strip
    color =''
    3.times {
    color << "%02x" % rand(255)
    @@ -43,7 +44,8 @@ class GitHub
    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
  3. robotarmy revised this gist Mar 31, 2012. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions import_issues.rb
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,8 @@ class GitHub
    password = get_input("Enter Password >", "*")
    GitHub.basic_auth user, password


    visited_labels = []
    FasterCSV.open filename, :headers => true do |csv|
    csv.each do |r|
    body = {
    @@ -35,12 +37,14 @@ class GitHub
    3.times {
    color << "%02x" % rand(255)
    }
    labels << {:name => label, :color =>color}
    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
  4. robotarmy revised this gist Mar 31, 2012. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions delete_labels.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #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
  5. robotarmy revised this gist Mar 31, 2012. No changes.
  6. robotarmy revised this gist Mar 31, 2012. 1 changed file with 37 additions and 8 deletions.
    45 changes: 37 additions & 8 deletions import_issues.rb
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,63 @@
    #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'
    basic_auth user, password

    end
    user = get_input("Enter Username >")
    password = get_input("Enter Password >", "*")
    GitHub.basic_auth user, password

    FasterCSV.open ARGV.shift, :headers => true do |csv|
    FasterCSV.open filename, :headers => true do |csv|
    csv.each do |r|
    # POST /repos/nko2/website/issues
    # title, body, assignee, milestone, labels
    body = {
    :title => r['Story'],
    :body => r['Description'],
    }
    body[:labels] = [ r['Labels'] ] if r['Labels'] != ''
    issue = GitHub.post '/repos/nko2/website/issues', :body => JSON.generate(body)
    labels = []

    if r['Labels'] != ''
    r['Labels'].split(',').each do |label|
    color =''
    3.times {
    color << "%02x" % rand(255)
    }
    labels << {:name => label, :color =>color}
    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
    label = GitHub.post '/repos/robotarmy/driveless/labels', :body => JSON.generate(label)
    p label
    end
    end

    body[:labels] = r['Labels'].split(',') 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]
    # POST /repos/nko2/website/issues/:id/comments
    body = { :body => f[1] }
    GitHub.post "/repos/nko2/website/issues/#{issue.parsed_response['number']}/comments", :body => JSON.generate(body)
    GitHub.post "/repos/robotarmy/driveless/issues/#{issue.parsed_response['number']}/comments", :body => JSON.generate(body)
    end
    end
    end
  7. visnu pitiyanuvath created this gist Jul 31, 2011.
    35 changes: 35 additions & 0 deletions import_issues.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/usr/bin/env ruby

    require 'rubygems'
    require 'FasterCSV'
    require 'httparty'
    require 'json'

    class GitHub
    include HTTParty
    base_uri 'https://api.github.com'
    basic_auth user, password
    end

    FasterCSV.open ARGV.shift, :headers => true do |csv|
    csv.each do |r|
    # POST /repos/nko2/website/issues
    # title, body, assignee, milestone, labels
    body = {
    :title => r['Story'],
    :body => r['Description'],
    }
    body[:labels] = [ r['Labels'] ] if r['Labels'] != ''
    issue = GitHub.post '/repos/nko2/website/issues', :body => JSON.generate(body)
    p issue

    r.each do |f|
    if f[0] == 'Note'
    next unless f[1]
    # POST /repos/nko2/website/issues/:id/comments
    body = { :body => f[1] }
    GitHub.post "/repos/nko2/website/issues/#{issue.parsed_response['number']}/comments", :body => JSON.generate(body)
    end
    end
    end
    end