Skip to content

Instantly share code, notes, and snippets.

@danielnorberg
Forked from tagomoris/github_org_clone_all.rb
Last active March 23, 2016 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielnorberg/81e27ddbe931686ea5a2 to your computer and use it in GitHub Desktop.
Save danielnorberg/81e27ddbe931686ea5a2 to your computer and use it in GitHub Desktop.
Script to clone all repositories of specified organization
#!/usr/bin/env ruby
# brew install parallel
# gem i github_api
## Setting -> Applications -> Personal Access Tokens -> Generate new token
# Selected scopes:
# * repo
# * public_repo
# * repo:status
# * read:org
## Generate token -> copy token and paste to "oauth_token"
# ruby github_org_clone_all.rb | parallel -P <desired parallelism>
oauth_token = "...."
org_name = 'yourcompany'
exists = Dir.glob('*')
require 'github_api'
github = Github.new(basic_auth: oauth_token)
pagenum = 1
list = []
while page = github.repos.list(org: org_name, page: pagenum, per_page: 100)
break if page.size < 1
list += page.to_a
pagenum += 1
end
dup = list.select{|repo| exists.include?(repo["name"]) }
puts "skipping #{dup.size} repositories which already exists.\n"
list = list.select{|repo| ! exists.include?(repo["name"]) }
puts "cloning #{list.size} repositories.\n"
list.each do |repo|
puts "git clone #{repo["ssh_url"]}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment