Commit e3a7e43ff4fb1ebf9e594b32abcb980a8b905c49

Authored by Riyad Preukschas
1 parent d188adfd

Rename gitlab:activate_namespaces to gitlab:enable_namespaces

doc/raketasks/features.md
1 ### Enable usernames and namespaces for user projects 1 ### Enable usernames and namespaces for user projects
2 2
3 -This command will enable the namespace feature introduced in v4.0. It will move every project in its namespace folder. 3 +This command will enable the namespaces feature introduced in v4.0. It will move every project in its namespace folder.
4 4
5 Note: 5 Note:
6 6
@@ -13,7 +13,7 @@ Old path: `git@example.org:myrepo.git` @@ -13,7 +13,7 @@ Old path: `git@example.org:myrepo.git`
13 New path: `git@example.org:username/myrepo.git` or `git@example.org:groupname/myrepo.git` 13 New path: `git@example.org:username/myrepo.git` or `git@example.org:groupname/myrepo.git`
14 14
15 ``` 15 ```
16 -bundle exec rake gitlab:activate_namespaces 16 +bundle exec rake gitlab:enable_namespaces
17 ``` 17 ```
18 18
19 19
lib/tasks/gitlab/activate_namespaces.rake
@@ -1,67 +0,0 @@ @@ -1,67 +0,0 @@
1 -namespace :gitlab do  
2 - desc "GITLAB | Enable usernames and namespaces for user projects"  
3 - task activate_namespaces: :environment do  
4 - print "\nUsernames for users:".yellow  
5 -  
6 - User.find_each(batch_size: 500) do |user|  
7 - next if user.namespace  
8 -  
9 - User.transaction do  
10 - username = user.email.match(/^[^@]*/)[0]  
11 - if user.update_attributes!(username: username)  
12 - print '.'.green  
13 - else  
14 - print 'F'.red  
15 - end  
16 - end  
17 - end  
18 -  
19 - print "\n\nDirs for groups:".yellow  
20 -  
21 - Group.find_each(batch_size: 500) do |group|  
22 - if group.ensure_dir_exist  
23 - print '.'.green  
24 - else  
25 - print 'F'.red  
26 - end  
27 - end  
28 -  
29 - print "\n\nMove projects from groups under groups dirs:".yellow  
30 - git_path = Gitlab.config.gitolite.repos_path  
31 -  
32 - Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|  
33 - next unless project.group  
34 -  
35 - group = project.group  
36 -  
37 - puts "\n"  
38 - print " * #{project.name}: "  
39 -  
40 - new_path = File.join(git_path, project.path_with_namespace + '.git')  
41 -  
42 - if File.exists?(new_path)  
43 - print "ok. already at #{new_path}".cyan  
44 - next  
45 - end  
46 -  
47 - old_path = File.join(git_path, project.path + '.git')  
48 -  
49 - unless File.exists?(old_path)  
50 - print "missing. not found at #{old_path}".red  
51 - next  
52 - end  
53 -  
54 - begin  
55 - Gitlab::ProjectMover.new(project, '', group.path).execute  
56 - print "ok. Moved to #{new_path}".green  
57 - rescue  
58 - print "Failed moving to #{new_path}".red  
59 - end  
60 - end  
61 -  
62 - print "\n\nRebuild gitolite:".yellow  
63 - gitolite = Gitlab::Gitolite.new  
64 - gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))  
65 - puts "\n"  
66 - end  
67 -end  
lib/tasks/gitlab/enable_namespaces.rake 0 → 100644
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
  1 +namespace :gitlab do
  2 + desc "GITLAB | Enable usernames and namespaces for user projects"
  3 + task enable_namespaces: :environment do
  4 + print "\nUsernames for users:".yellow
  5 +
  6 + User.find_each(batch_size: 500) do |user|
  7 + next if user.namespace
  8 +
  9 + User.transaction do
  10 + username = user.email.match(/^[^@]*/)[0]
  11 + if user.update_attributes!(username: username)
  12 + print '.'.green
  13 + else
  14 + print 'F'.red
  15 + end
  16 + end
  17 + end
  18 +
  19 + print "\n\nDirs for groups:".yellow
  20 +
  21 + Group.find_each(batch_size: 500) do |group|
  22 + if group.ensure_dir_exist
  23 + print '.'.green
  24 + else
  25 + print 'F'.red
  26 + end
  27 + end
  28 +
  29 + print "\n\nMove projects from groups under groups dirs:".yellow
  30 + git_path = Gitlab.config.gitolite.repos_path
  31 +
  32 + Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|
  33 + next unless project.group
  34 +
  35 + group = project.group
  36 +
  37 + puts "\n"
  38 + print " * #{project.name}: "
  39 +
  40 + new_path = File.join(git_path, project.path_with_namespace + '.git')
  41 +
  42 + if File.exists?(new_path)
  43 + print "ok. already at #{new_path}".cyan
  44 + next
  45 + end
  46 +
  47 + old_path = File.join(git_path, project.path + '.git')
  48 +
  49 + unless File.exists?(old_path)
  50 + print "missing. not found at #{old_path}".red
  51 + next
  52 + end
  53 +
  54 + begin
  55 + Gitlab::ProjectMover.new(project, '', group.path).execute
  56 + print "ok. Moved to #{new_path}".green
  57 + rescue
  58 + print "Failed moving to #{new_path}".red
  59 + end
  60 + end
  61 +
  62 + print "\n\nRebuild gitolite:".yellow
  63 + gitolite = Gitlab::Gitolite.new
  64 + gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))
  65 + puts "\n"
  66 + end
  67 +end