Skip to content

Instantly share code, notes, and snippets.

@akatz
Created April 14, 2013 00:45
Show Gist options
  • Save akatz/5380822 to your computer and use it in GitHub Desktop.
Save akatz/5380822 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
require 'json'
require "highline/import"
trap("INT") do
system "stty echo"
exit
end
class RepoSyncer
IGNORED_REPOS=["Design-Assets"]
def initialize(username,password,organization)
@username = username
@password = password
@organization = organization
end
def sync
uri = URI.parse("https://api.github.com/orgs/#{@organization}/repos")
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new uri.request_uri
request.basic_auth @username, @password
response = http.request request # Net::HTTPResponse object
end
JSON.parse(response.body).map {|x| x["ssh_url"] }.each do |url|
repo = url.split("/").last.gsub("\.git","")
next if IGNORED_REPOS.include?(repo)
if Dir.exists?(repo)
Dir.chdir(repo)
puts "fetching changes to #{repo}"
%x[git pull]
Dir.chdir("..")
else
puts "cloning repo #{url}"
%x[git clone #{url}]
end
end
end
end
organization = ask("What github organization do you want to clone? ")
username = ask("What is your github username? ")
password = ask("What is your github password? ") { |q| q.echo = false }
RepoSyncer.new(username, password, organization).sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment