gitlab-org--gitlab-foss/lib/tasks/gitlab/import.rake
Connor Shea 903946c78a
Replace colorize gem with rainbow.
Colorize is a gem licensed under the GPLv2, so we can’t use it in GitLab without relicensing GitLab under the terms of the GPL. Rainbow is licensed under the MIT license and does the exact same thing as Colorize, so Rainbow was added in place of Colorize.

The syntax is slightly different for Rainbow vs. Colorize, and was updated in accordance.

The gem is still a dependency of Spinach, so it’s included in the development/test environments, but won’t be packaged with the actual product, and therefore doesn’t require we relicense the product.

An attempt at relicensing Colorize was made, but didn’t succeed as the library owner never responded.

Rainbow library: https://github.com/sickill/rainbow
Relevant issue regarding licensing in GitLab's gems: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3775
2016-06-03 10:37:09 -06:00

79 lines
2.4 KiB
Ruby

namespace :gitlab do
namespace :import do
# How to use:
#
# 1. copy the bare repos under the repos_path (commonly /home/git/repositories)
# 2. run: bundle exec rake gitlab:import:repos RAILS_ENV=production
#
# Notes:
# * The project owner will set to the first administator of the system
# * Existing projects will be skipped
#
desc "GitLab | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance"
task repos: :environment do
git_base_path = Gitlab.config.gitlab_shell.repos_path
repos_to_import = Dir.glob(git_base_path + '/**/*.git')
repos_to_import.each do |repo_path|
# strip repo base path
repo_path[0..git_base_path.length] = ''
path = repo_path.sub(/\.git$/, '')
group_name, name = File.split(path)
group_name = nil if group_name == '.'
puts "Processing #{repo_path}".color(:yellow)
if path.end_with?('.wiki')
puts " * Skipping wiki repo"
next
end
project = Project.find_with_namespace(path)
if project
puts " * #{project.name} (#{repo_path}) exists"
else
user = User.admins.reorder("id").first
project_params = {
name: name,
path: name
}
# find group namespace
if group_name
group = Namespace.find_by(path: group_name)
# create group namespace
unless group
group = Group.new(:name => group_name)
group.path = group_name
group.owner = user
if group.save
puts " * Created Group #{group.name} (#{group.id})".color(:green)
else
puts " * Failed trying to create group #{group.name}".color(:red)
end
end
# set project group
project_params[:namespace_id] = group.id
end
project = Projects::CreateService.new(user, project_params).execute
if project.persisted?
puts " * Created #{project.name} (#{repo_path})".color(:green)
project.update_repository_size
project.update_commit_count
else
puts " * Failed trying to create #{project.name} (#{repo_path})".color(:red)
puts " Errors: #{project.errors.messages}".color(:red)
end
end
end
puts "Done!".color(:green)
end
end
end