Skip to content

Instantly share code, notes, and snippets.

@oliverlundquist
Created August 31, 2015 04:23
Show Gist options
  • Save oliverlundquist/0bca3935652c4a92d556 to your computer and use it in GitHub Desktop.
Save oliverlundquist/0bca3935652c4a92d556 to your computer and use it in GitHub Desktop.
Sync GitHub Labels
require 'rubygems'
require 'bundler/setup'
require 'uri'
require 'rest-client'
require 'json'
username = ''
password = ''
origin = "https://#{username}:#{password}@api.github.com/repos/kurashicom/cart/labels"
destination = "https://#{username}:#{password}@api.github.com/repos/kurashicom/evaluation/labels"
origin_labels = JSON.parse(RestClient.get(origin), symbolize_names: true)
destination_labels = JSON.parse(RestClient.get(destination), symbolize_names: true)
destination_labels.each do |label|
puts "Deleting: #{label[:name]}"
RestClient.delete(URI.encode("#{destination}/#{label[:name]}"))
end
origin_labels.each do |label|
puts "Adding: #{label[:name]} (##{label[:color]})"
RestClient.post(destination, { name: label[:name], color: label[:color] }.to_json, content_type: :json, accept: :json)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment