Created
October 29, 2016 17:27
-
-
Save zach-taylor/ce2031693b94d2e6d243b1b3c909adac to your computer and use it in GitHub Desktop.
Rake script to migrate all repos from Bitbucket org to Github org
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
# gem install bitbucket_rest_api | |
# gem install octokit | |
require 'bitbucket_rest_api' | |
require 'octokit' | |
task :migrate do | |
bitbucket = BitBucket.new login: '', password: '' | |
bitbucket_owner = '' | |
github = Octokit::Client.new login: '', password: '' | |
github_org = '' | |
bitbucket.repos.list do |repo| | |
next unless repo.owner == bitbucket_owner | |
if github.repository?("#{github_org}/#{repo.slug}") | |
puts "#{repo.slug} exists! =================================" | |
else | |
github.create_repo(repo.slug, organization: github_org, private: true) | |
url = "https://bitbucket.org/#{repo.owner}/#{repo.slug}" | |
system("mkdir #{repo.slug}") | |
system("git clone --mirror #{url} #{repo.slug}/.git") | |
Dir.chdir(repo.slug) do | |
system("git config --bool core.bare false") | |
system("git remote add gh https://github.com/#{github_org}/#{repo.slug}") | |
system("git push --all gh") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment