Commit 6ba4cb1d2b0bcfaf8459c8936513637acc92da5e

Authored by Dmitriy Zaporozhets
1 parent 260c877c

Remove old rake task

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing 1 changed file with 0 additions and 111 deletions   Show diff stats
lib/tasks/gitlab/enable_namespaces.rake
@@ -1,111 +0,0 @@ @@ -1,111 +0,0 @@
1 -namespace :gitlab do  
2 - desc "GITLAB | Enable usernames and namespaces for user projects"  
3 - task enable_namespaces: :environment do  
4 - warn_user_is_not_gitlab  
5 -  
6 - migrate_user_namespaces  
7 - migrate_groups  
8 - migrate_projects  
9 - end  
10 -  
11 - def migrate_user_namespaces  
12 - puts "\nGenerate usernames for users without one: ".blue  
13 - User.find_each(batch_size: 500) do |user|  
14 - if user.namespace  
15 - print '-'.cyan  
16 - next  
17 - end  
18 -  
19 - username = if user.username.present?  
20 - # if user already has username filled  
21 - user.username  
22 - else  
23 - build_username(user)  
24 - end  
25 -  
26 - begin  
27 - User.transaction do  
28 - user.update_attributes!(username: username)  
29 - print '.'.green  
30 - end  
31 - rescue  
32 - print 'F'.red  
33 - end  
34 - end  
35 - puts "\nDone"  
36 - end  
37 -  
38 - def build_username(user)  
39 - username = nil  
40 -  
41 - # generate username  
42 - username = user.email.match(/^[^@]*/)[0]  
43 - username.gsub!("+", ".")  
44 -  
45 - # return username if no matches  
46 - return username unless User.find_by(username: username)  
47 -  
48 - # look for same username  
49 - (1..10).each do |i|  
50 - suffixed_username = "#{username}#{i}"  
51 -  
52 - return suffixed_username unless User.find_by(username: suffixed_username)  
53 - end  
54 - end  
55 -  
56 - def migrate_groups  
57 - puts "\nCreate directories for groups: ".blue  
58 -  
59 - Group.find_each(batch_size: 500) do |group|  
60 - begin  
61 - if group.dir_exists?  
62 - print '-'.cyan  
63 - else  
64 - if group.ensure_dir_exist  
65 - print '.'.green  
66 - else  
67 - print 'F'.red  
68 - end  
69 - end  
70 - rescue  
71 - print 'F'.red  
72 - end  
73 - end  
74 - puts "\nDone"  
75 - end  
76 -  
77 - def migrate_projects  
78 - git_path = Gitlab.config.gitlab_shell.repos_path  
79 - puts "\nMove projects in groups into respective directories ... ".blue  
80 - Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|  
81 - next unless project.group  
82 -  
83 - group = project.group  
84 -  
85 - print "#{project.name_with_namespace.yellow} ... "  
86 -  
87 - new_path = File.join(git_path, project.path_with_namespace + '.git')  
88 -  
89 - if File.exists?(new_path)  
90 - puts "already at #{new_path}".green  
91 - next  
92 - end  
93 -  
94 - old_path = File.join(git_path, project.path + '.git')  
95 -  
96 - unless File.exists?(old_path)  
97 - puts "couldn't find it at #{old_path}".red  
98 - next  
99 - end  
100 -  
101 - begin  
102 - project.transfer(group.path)  
103 - puts "moved to #{new_path}".green  
104 - rescue  
105 - puts "failed moving to #{new_path}".red  
106 - end  
107 - end  
108 -  
109 - puts "\nDone"  
110 - end  
111 -end