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
Kazuhiko Shiozaki
gitlab-ce
Commits
d03964d6
Commit
d03964d6
authored
Dec 28, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed and improved enable_naamespace migration task
parent
d991ce63
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
22 deletions
+71
-22
app/models/namespace.rb
app/models/namespace.rb
+5
-1
app/observers/user_observer.rb
app/observers/user_observer.rb
+1
-1
lib/tasks/gitlab/enable_namespaces.rake
lib/tasks/gitlab/enable_namespaces.rake
+65
-20
No files found.
app/models/namespace.rb
View file @
d03964d6
...
@@ -51,8 +51,12 @@ class Namespace < ActiveRecord::Base
...
@@ -51,8 +51,12 @@ class Namespace < ActiveRecord::Base
end
end
def
ensure_dir_exist
def
ensure_dir_exist
dir_exists?
||
system
(
"mkdir -m 770
#{
namespace_dir_path
}
"
)
end
def
dir_exists?
namespace_dir_path
=
File
.
join
(
Gitlab
.
config
.
gitolite
.
repos_path
,
path
)
namespace_dir_path
=
File
.
join
(
Gitlab
.
config
.
gitolite
.
repos_path
,
path
)
system
(
"mkdir -m 770
#{
namespace_dir_path
}
"
)
unless
File
.
exists?
(
namespace_dir_path
)
File
.
exists?
(
namespace_dir_path
)
end
end
def
move_dir
def
move_dir
...
...
app/observers/user_observer.rb
View file @
d03964d6
...
@@ -14,7 +14,7 @@ class UserObserver < ActiveRecord::Observer
...
@@ -14,7 +14,7 @@ class UserObserver < ActiveRecord::Observer
if
user
.
namespace
if
user
.
namespace
user
.
namespace
.
update_attributes
(
path:
user
.
username
)
user
.
namespace
.
update_attributes
(
path:
user
.
username
)
else
else
user
.
create_namespace!
(
path:
user
.
username
,
name:
user
.
name
)
user
.
create_namespace!
(
path:
user
.
username
,
name:
user
.
user
name
)
end
end
end
end
end
end
...
...
lib/tasks/gitlab/enable_namespaces.rake
View file @
d03964d6
...
@@ -3,36 +3,85 @@ namespace :gitlab do
...
@@ -3,36 +3,85 @@ namespace :gitlab do
task
enable_namespaces: :environment
do
task
enable_namespaces: :environment
do
warn_user_is_not_gitlab
warn_user_is_not_gitlab
print
"Generate usernames for users without one: "
migrate_user_namespaces
migrate_groups
migrate_projects
puts
"Rebuild Gitolite ... "
gitolite
=
Gitlab
::
Gitolite
.
new
gitolite
.
update_repositories
(
Project
.
where
(
'namespace_id IS NOT NULL'
))
puts
"...
#{
"done"
.
green
}
"
end
def
migrate_user_namespaces
puts
"
\n
Generate usernames for users without one: "
.
blue
User
.
find_each
(
batch_size:
500
)
do
|
user
|
User
.
find_each
(
batch_size:
500
)
do
|
user
|
next
if
user
.
namespace
if
user
.
namespace
print
'-'
.
cyan
next
end
User
.
transaction
do
username
=
if
user
.
username
.
present?
username
=
user
.
email
.
match
(
/^[^@]*/
)[
0
]
# if user already has username filled
if
user
.
update_attributes!
(
username:
username
)
user
.
username
else
build_username
(
user
)
end
begin
User
.
transaction
do
user
.
update_attributes!
(
username:
username
)
print
'.'
.
green
print
'.'
.
green
else
print
'F'
.
red
end
end
rescue
print
'F'
.
red
end
end
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 mathes
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
puts
""
def
migrate_groups
p
rint
"Create directories for groups: "
p
uts
"
\n
Create directories for groups: "
.
blue
Group
.
find_each
(
batch_size:
500
)
do
|
group
|
Group
.
find_each
(
batch_size:
500
)
do
|
group
|
if
group
.
ensure_dir_exist
begin
print
'.'
.
green
if
group
.
dir_exists?
else
print
'-'
.
cyan
else
if
group
.
ensure_dir_exist
print
'.'
.
green
else
print
'F'
.
red
end
end
rescue
print
'F'
.
red
print
'F'
.
red
end
end
end
end
puts
""
puts
"
\n
Done"
end
def
migrate_projects
git_path
=
Gitlab
.
config
.
gitolite
.
repos_path
git_path
=
Gitlab
.
config
.
gitolite
.
repos_path
puts
""
puts
"
\n
Move projects in groups into respective directories ... "
.
blue
puts
"Move projects in groups into respective directories ... "
Project
.
where
(
'namespace_id IS NOT NULL'
).
find_each
(
batch_size:
500
)
do
|
project
|
Project
.
where
(
'namespace_id IS NOT NULL'
).
find_each
(
batch_size:
500
)
do
|
project
|
next
unless
project
.
group
next
unless
project
.
group
...
@@ -62,10 +111,6 @@ namespace :gitlab do
...
@@ -62,10 +111,6 @@ namespace :gitlab do
end
end
end
end
puts
""
puts
"
\n
Done"
puts
"Rebuild Gitolite ... "
gitolite
=
Gitlab
::
Gitolite
.
new
gitolite
.
update_repositories
(
Project
.
where
(
'namespace_id IS NOT NULL'
))
puts
"...
#{
"done"
.
green
}
"
end
end
end
end
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