Last active
December 14, 2015 03:39
-
-
Save arangamani/5022951 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
if ARGV.size != 1 | |
puts "This script only accepts a single parameter as organization." | |
puts "Usage: #{__FILE__.split("/").last} <organization>" | |
exit 1 | |
end | |
repo_urls = [] | |
page = 1 | |
org = ARGV.first | |
while true | |
data = `curl -s https://api.github.com/orgs/#{org}/repos?page=#{page}` | |
json_data = JSON.load(data) | |
# Response will be empty if there are no more repositories in a page | |
break if json_data.empty? | |
# If the API rate limit is exceeded display a message and exit | |
puts json_data | |
#if json_data.is_a? Hash && !json_data["message"].nil? && | |
# json_data["message"] =~ /API Rate Limit Exceeded/ | |
# raise "API rate limit exceeded" | |
#end | |
json_data.each do |repo| | |
repo_urls << repo["ssh_url"] if repo | |
end | |
puts "Visited page: #{page}. Repos found so far: #{repo_urls.length}" | |
page += 1 | |
end | |
puts repo_urls | |
puts "Total Repos found: #{repo_urls.length}" | |
repo_urls.each do |url| | |
puts "Clonning to: #{url}..." | |
%x[git clone #{url}] | |
end | |
puts "All repositories are downloaded successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment