BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
6831ee8f
Commit
6831ee8f
authored
Apr 05, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/import-namespace' into 'master'
Create subgroups if they don't exist while importing projects See merge request !10406
parents
65ea732c
bdcd23b2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
206 additions
and
6 deletions
+206
-6
base_controller.rb
app/controllers/import/base_controller.rb
+15
-5
fix-import-namespace.yml
changelogs/unreleased/fix-import-namespace.yml
+4
-0
bitbucket_controller_spec.rb
spec/controllers/import/bitbucket_controller_spec.rb
+67
-0
gitlab_controller_spec.rb
spec/controllers/import/gitlab_controller_spec.rb
+66
-0
githubish_import_controller_shared_examples.rb
...ontrollers/githubish_import_controller_shared_examples.rb
+54
-1
No files found.
app/controllers/import/base_controller.rb
View file @
6831ee8f
class
Import
::
BaseController
<
ApplicationController
class
Import
::
BaseController
<
ApplicationController
private
private
def
find_or_create_namespace
(
name
,
owner
)
def
find_or_create_namespace
(
name
s
,
owner
)
return
current_user
.
namespace
if
name
==
owner
return
current_user
.
namespace
if
name
s
==
owner
return
current_user
.
namespace
unless
current_user
.
can_create_group?
return
current_user
.
namespace
unless
current_user
.
can_create_group?
names
=
params
[
:target_namespace
].
presence
||
names
full_path_namespace
=
Namespace
.
find_by_full_path
(
names
)
return
full_path_namespace
if
full_path_namespace
names
.
split
(
'/'
).
inject
(
nil
)
do
|
parent
,
name
|
begin
begin
name
=
params
[
:target_namespace
].
presence
||
name
namespace
=
Group
.
create!
(
name:
name
,
namespace
=
Group
.
create!
(
name:
name
,
path:
name
,
owner:
current_user
)
path:
name
,
owner:
current_user
,
parent:
parent
)
namespace
.
add_owner
(
current_user
)
namespace
.
add_owner
(
current_user
)
namespace
namespace
rescue
ActiveRecord
::
RecordNotUnique
,
ActiveRecord
::
RecordInvalid
rescue
ActiveRecord
::
RecordNotUnique
,
ActiveRecord
::
RecordInvalid
Namespace
.
find_by_full_path
(
name
)
Namespace
.
where
(
parent:
parent
).
find_by_path_or_name
(
name
)
end
end
end
end
end
end
end
changelogs/unreleased/fix-import-namespace.yml
0 → 100644
View file @
6831ee8f
---
title
:
Create subgroups if they don't exist while importing projects
merge_request
:
author
:
spec/controllers/import/bitbucket_controller_spec.rb
View file @
6831ee8f
...
@@ -200,5 +200,72 @@ describe Import::BitbucketController do
...
@@ -200,5 +200,72 @@ describe Import::BitbucketController do
end
end
end
end
end
end
context
'user has chosen an existing nested namespace and name for the project'
do
let
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
let
(
:nested_namespace
)
{
create
(
:namespace
,
name:
'bar'
,
parent:
parent_namespace
,
owner:
user
)
}
let
(
:test_name
)
{
'test_name'
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
nested_namespace
,
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
new_name:
test_name
,
format: :js
}
end
end
context
'user has chosen a non-existent nested namespaces and name for the project'
do
let
(
:test_name
)
{
'test_name'
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
it
'new namespace has the right parent'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
expect
(
Namespace
.
find_by_path_or_name
(
'bar'
).
parent
.
path
).
to
eq
(
'foo'
)
end
end
context
'user has chosen existent and non-existent nested namespaces and name for the project'
do
let
(
:test_name
)
{
'test_name'
}
let!
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
BitbucketImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
bitbucket_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
end
end
end
end
end
spec/controllers/import/gitlab_controller_spec.rb
View file @
6831ee8f
...
@@ -174,6 +174,72 @@ describe Import::GitlabController do
...
@@ -174,6 +174,72 @@ describe Import::GitlabController do
end
end
end
end
end
end
context
'user has chosen an existing nested namespace for the project'
do
let
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
let
(
:nested_namespace
)
{
create
(
:namespace
,
name:
'bar'
,
parent:
parent_namespace
,
owner:
user
)
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
nested_namespace
,
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
format: :js
}
end
end
context
'user has chosen a non-existent nested namespaces for the project'
do
let
(
:test_name
)
{
'test_name'
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
it
'new namespace has the right parent'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
format: :js
}
expect
(
Namespace
.
find_by_path_or_name
(
'bar'
).
parent
.
path
).
to
eq
(
'foo'
)
end
end
context
'user has chosen existent and non-existent nested namespaces and name for the project'
do
let
(
:test_name
)
{
'test_name'
}
let!
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GitlabImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
gitlab_repo
,
kind_of
(
Namespace
),
user
,
access_params
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
end
end
end
end
end
end
end
spec/support/controllers/githubish_import_controller_shared_examples.rb
View file @
6831ee8f
...
@@ -229,7 +229,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do
...
@@ -229,7 +229,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do
end
end
end
end
context
'user has chosen a nested namespace and name for the project'
do
context
'user has chosen a
n existing
nested namespace and name for the project'
do
let
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
let
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
let
(
:nested_namespace
)
{
create
(
:namespace
,
name:
'bar'
,
parent:
parent_namespace
,
owner:
user
)
}
let
(
:nested_namespace
)
{
create
(
:namespace
,
name:
'bar'
,
parent:
parent_namespace
,
owner:
user
)
}
let
(
:test_name
)
{
'test_name'
}
let
(
:test_name
)
{
'test_name'
}
...
@@ -242,5 +242,58 @@ shared_examples 'a GitHub-ish import controller: POST create' do
...
@@ -242,5 +242,58 @@ shared_examples 'a GitHub-ish import controller: POST create' do
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
new_name:
test_name
,
format: :js
}
post
:create
,
{
target_namespace:
nested_namespace
.
full_path
,
new_name:
test_name
,
format: :js
}
end
end
end
end
context
'user has chosen a non-existent nested namespaces and name for the project'
do
let
(
:test_name
)
{
'test_name'
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GithubImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
provider_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
,
type:
provider
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GithubImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
provider_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
,
type:
provider
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
it
'new namespace has the right parent'
do
allow
(
Gitlab
::
GithubImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
provider_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
,
type:
provider
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/bar'
,
new_name:
test_name
,
format: :js
}
expect
(
Namespace
.
find_by_path_or_name
(
'bar'
).
parent
.
path
).
to
eq
(
'foo'
)
end
end
context
'user has chosen existent and non-existent nested namespaces and name for the project'
do
let
(
:test_name
)
{
'test_name'
}
let!
(
:parent_namespace
)
{
create
(
:namespace
,
name:
'foo'
,
owner:
user
)
}
it
'takes the selected namespace and name'
do
expect
(
Gitlab
::
GithubImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
provider_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
,
type:
provider
).
and_return
(
double
(
execute:
true
))
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
end
it
'creates the namespaces'
do
allow
(
Gitlab
::
GithubImport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
provider_repo
,
test_name
,
kind_of
(
Namespace
),
user
,
access_params
,
type:
provider
).
and_return
(
double
(
execute:
true
))
expect
{
post
:create
,
{
target_namespace:
'foo/foobar/bar'
,
new_name:
test_name
,
format: :js
}
}
.
to
change
{
Namespace
.
count
}.
by
(
2
)
end
end
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