Last active
March 27, 2020 03:23
-
-
Save tagomoris/1394916845a1b8020e43 to your computer and use it in GitHub Desktop.
Script to clone all repositories of specified organization
This file contains 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 | |
# 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" | |
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| | |
system "git clone #{repo["ssh_url"]}" | |
sleep 5 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a magic number. I know how engineers in github.com thinks :)