Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active December 8, 2016 00:19
Show Gist options
  • Select an option

  • Save zeroeth/8f8bff8ddc5e5084d2ffab65bc84666e to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/8f8bff8ddc5e5084d2ffab65bc84666e to your computer and use it in GitHub Desktop.
Script to help mirror fork a bunch of repos at once.
# Fork all repos from one user to another
# Will skip any repos with same name
require 'octokit'
# Put your desired user/orgs here
origin = 'user1'
destination = 'org1'
destination_is_organization = true
# Put your Personal Access Token with Admin rights to create repos here.
access_token = 'replace me'
Octokit.auto_paginate = true
# End Config
#
repos = [] # Want to Fork
mirrors = [] # Forked previously
forks = [] # Forked this run
# Authentication #########################
#
client = Octokit::Client.new access_token: access_token
user = client.user
user.login
puts "Api Rate: #{client.rate_limit}"
# Fetch Repo Lists #######################
#
puts "Getting Repos ..."
repos = client.repos origin
puts "Getting Mirrors ..."
mirrors = client.repos destination
puts "Will Fork #{origin} [#{repos.count}] to #{destination}"
# Fork ###################################
#
mirror_names = mirrors.collect(&:name)
repos.each do |repo|
if(mirror_names.include? repo.name)
puts "SKIP #{repo.full_name}"
else
puts ".. #{repo.full_name}"
options = {}
if destination_is_organization
options[:organization] = destination
end
repo_fork = client.fork repo.full_name, options
forks.push repo_fork
end
end
puts "Forked #{forks.count} repos."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment