Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6ba4cb1d
Commit
6ba4cb1d
authored
10 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old rake task
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
260c877c
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
111 deletions
+0
-111
lib/tasks/gitlab/enable_namespaces.rake
lib/tasks/gitlab/enable_namespaces.rake
+0
-111
No files found.
lib/tasks/gitlab/enable_namespaces.rake
deleted
100644 → 0
View file @
260c877c
namespace
:gitlab
do
desc
"GITLAB | Enable usernames and namespaces for user projects"
task
enable_namespaces: :environment
do
warn_user_is_not_gitlab
migrate_user_namespaces
migrate_groups
migrate_projects
end
def
migrate_user_namespaces
puts
"
\n
Generate usernames for users without one: "
.
blue
User
.
find_each
(
batch_size:
500
)
do
|
user
|
if
user
.
namespace
print
'-'
.
cyan
next
end
username
=
if
user
.
username
.
present?
# if user already has username filled
user
.
username
else
build_username
(
user
)
end
begin
User
.
transaction
do
user
.
update_attributes!
(
username:
username
)
print
'.'
.
green
end
rescue
print
'F'
.
red
end
end
puts
"
\n
Done"
end
def
build_username
(
user
)
username
=
nil
# generate username
username
=
user
.
email
.
match
(
/^[^@]*/
)[
0
]
username
.
gsub!
(
"+"
,
"."
)
# return username if no matches
return
username
unless
User
.
find_by
(
username:
username
)
# look for same username
(
1
..
10
).
each
do
|
i
|
suffixed_username
=
"
#{
username
}#{
i
}
"
return
suffixed_username
unless
User
.
find_by
(
username:
suffixed_username
)
end
end
def
migrate_groups
puts
"
\n
Create directories for groups: "
.
blue
Group
.
find_each
(
batch_size:
500
)
do
|
group
|
begin
if
group
.
dir_exists?
print
'-'
.
cyan
else
if
group
.
ensure_dir_exist
print
'.'
.
green
else
print
'F'
.
red
end
end
rescue
print
'F'
.
red
end
end
puts
"
\n
Done"
end
def
migrate_projects
git_path
=
Gitlab
.
config
.
gitlab_shell
.
repos_path
puts
"
\n
Move projects in groups into respective directories ... "
.
blue
Project
.
where
(
'namespace_id IS NOT NULL'
).
find_each
(
batch_size:
500
)
do
|
project
|
next
unless
project
.
group
group
=
project
.
group
print
"
#{
project
.
name_with_namespace
.
yellow
}
... "
new_path
=
File
.
join
(
git_path
,
project
.
path_with_namespace
+
'.git'
)
if
File
.
exists?
(
new_path
)
puts
"already at
#{
new_path
}
"
.
green
next
end
old_path
=
File
.
join
(
git_path
,
project
.
path
+
'.git'
)
unless
File
.
exists?
(
old_path
)
puts
"couldn't find it at
#{
old_path
}
"
.
red
next
end
begin
project
.
transfer
(
group
.
path
)
puts
"moved to
#{
new_path
}
"
.
green
rescue
puts
"failed moving to
#{
new_path
}
"
.
red
end
end
puts
"
\n
Done"
end
end
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment