Last active
February 10, 2017 14:48
-
-
Save sadikay/7e6477824f9bd85489a1715d17d414d6 to your computer and use it in GitHub Desktop.
moving groups repos between gitlab accounts
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
require 'json' | |
PRIVATE_TOKEN = "" | |
NEW_PRIVATE_TOKEN = "" | |
OLD_GITLAB_URL = "" | |
NEW_GITLAB_URL = "http://gitlab.org/api/v3" | |
PATH = "" | |
res = `curl --header "PRIVATE-TOKEN: #{PRIVATE_TOKEN}" #{OLD_GITLAB_URL}/groups/` | |
groups = JSON.parse res | |
groups.each do |group| | |
# Creating New Remote Groups | |
begin | |
puts "#{group['name']}" | |
new_group = `curl --request POST --header "PRIVATE-TOKEN: #{NEW_PRIVATE_TOKEN}" "https://gitlab.com/api/v3/groups?name=mll-old-#{group['name']}&path=mll-old-#{group['name']}"` | |
new_group = JSON.parse new_group | |
puts "#{new_group['name']}" | |
rescue => e | |
puts e | |
end | |
# Cloning old repos to local | |
begin | |
repos = `curl --header "PRIVATE-TOKEN: #{PRIVATE_TOKEN}" #{OLD_GITLAB_URL}/groups/#{group['id']}/projects/` | |
repos = JSON.parse repos | |
`cd #{PATH} && mkdir #{group['name'].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')} && cd "$_"` | |
repos.each do |repo| | |
`git clone #{repo['ssh_url_to_repo']}` | |
puts "NEW REPO: #{repo['name']} : #{group['name']}" | |
puts "--------------------------------------------\n" | |
end | |
rescue => e | |
puts e | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment