Created
September 3, 2020 09:31
-
-
Save aozisik/7a37371c60dfe3702a24e49f37512b74 to your computer and use it in GitHub Desktop.
Ruby script to transfer multiple GitHub repos in one go
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
# How to use: | |
# 1- Fill in fromHandle, toHandle, personalAccessToken and repositories | |
# 2- Run this script from Terminal: | |
# | |
# ruby ./github-transfer.rb | |
# | |
# 3- There's no step 3. | |
require 'json' | |
require 'uri' | |
require 'net/http' | |
# Who's the current owner? | |
fromHandle = "source-user" | |
# Who's the new owner (it could be an organization name as well) | |
toHandle = "target-user" | |
# Go to https://github.com/settings/tokens | |
# Under personal access tokens, create a new token | |
# with all the "repo" permissions | |
personalAccessToken = "your-token-goes-here" | |
# List of repositories go here | |
# Note: Add only the repo names, without "username/" | |
repositories = [ | |
"repo-1" | |
"repo-2" | |
] | |
puts "🚢 Transferring your Github Repositories..." | |
repositories.each do |repo| | |
puts "Transferring #{fromHandle}/#{repo}..." | |
response = Net::HTTP.post URI("https://api.github.com/repos/#{fromHandle}/#{repo}/transfer"), | |
{ "new_owner" => toHandle }.to_json, | |
{ | |
"Accept" => "application/vnd.github.v3+json", | |
"Authorization" => "token #{personalAccessToken}", | |
"Content-Type" => "application/json" | |
} | |
puts response | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment