2012-11-23 04:34:09 +01:00
|
|
|
namespace :gitlab do
|
|
|
|
desc "GITLAB | Enable usernames and namespaces for user projects"
|
|
|
|
task activate_namespaces: :environment do
|
2012-11-25 17:24:27 +01:00
|
|
|
print "\nUsernames for users:".yellow
|
|
|
|
|
2012-11-23 04:34:09 +01:00
|
|
|
User.find_each(batch_size: 500) do |user|
|
2012-11-24 11:25:04 +01:00
|
|
|
next if user.namespace
|
|
|
|
|
2012-11-23 04:34:09 +01:00
|
|
|
User.transaction do
|
|
|
|
username = user.email.match(/^[^@]*/)[0]
|
2012-11-24 11:25:04 +01:00
|
|
|
if user.update_attributes!(username: username)
|
|
|
|
print '.'.green
|
|
|
|
else
|
|
|
|
print 'F'.red
|
|
|
|
end
|
2012-11-23 04:34:09 +01:00
|
|
|
end
|
|
|
|
end
|
2012-11-25 16:58:06 +01:00
|
|
|
|
2012-11-25 17:24:27 +01:00
|
|
|
print "\n\nDirs for groups:".yellow
|
|
|
|
|
2012-11-25 16:58:06 +01:00
|
|
|
Group.find_each(batch_size: 500) do |group|
|
|
|
|
if group.ensure_dir_exist
|
|
|
|
print '.'.green
|
|
|
|
else
|
|
|
|
print 'F'.red
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-25 17:24:27 +01:00
|
|
|
print "\n\nMove projects from groups under groups dirs:".yellow
|
2012-11-25 16:58:06 +01:00
|
|
|
git_path = Gitlab.config.git_base_path
|
|
|
|
|
|
|
|
Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|
|
|
|
|
next unless project.group
|
|
|
|
|
|
|
|
group = project.group
|
|
|
|
|
2012-11-25 17:24:27 +01:00
|
|
|
puts "\n"
|
|
|
|
print " * #{project.name}: "
|
|
|
|
|
|
|
|
new_path = File.join(git_path, project.path_with_namespace + '.git')
|
|
|
|
|
|
|
|
if File.exists?(new_path)
|
|
|
|
print "ok. already at #{new_path}".cyan
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
old_path = File.join(git_path, project.path + '.git')
|
2012-11-25 16:58:06 +01:00
|
|
|
|
2012-11-25 17:24:27 +01:00
|
|
|
unless File.exists?(old_path)
|
|
|
|
print "missing. not found at #{old_path}".red
|
|
|
|
next
|
|
|
|
end
|
2012-11-25 16:58:06 +01:00
|
|
|
|
|
|
|
begin
|
|
|
|
Gitlab::ProjectMover.new(project, '', group.path).execute
|
2012-11-25 17:24:27 +01:00
|
|
|
print "ok. Moved to #{new_path}".green
|
2012-11-25 16:58:06 +01:00
|
|
|
rescue
|
2012-11-25 17:24:27 +01:00
|
|
|
print "Failed moving to #{new_path}".red
|
2012-11-25 16:58:06 +01:00
|
|
|
end
|
|
|
|
end
|
2012-11-25 17:24:27 +01:00
|
|
|
|
|
|
|
print "\n\nRebuild gitolite:".yellow
|
|
|
|
gitolite = Gitlab::Gitolite.new
|
|
|
|
gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))
|
|
|
|
puts "\n"
|
2012-11-23 04:34:09 +01:00
|
|
|
end
|
|
|
|
end
|