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
Léo-Paul Géneau
gitlab-ce
Commits
e613d777
Commit
e613d777
authored
Feb 14, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code based on feedback
parent
08319490
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
15 deletions
+30
-15
lib/api/project_import.rb
lib/api/project_import.rb
+10
-7
spec/requests/api/project_import_spec.rb
spec/requests/api/project_import_spec.rb
+20
-8
No files found.
lib/api/project_import.rb
View file @
e613d777
...
@@ -10,19 +10,24 @@ module API
...
@@ -10,19 +10,24 @@ module API
def
file_is_valid?
def
file_is_valid?
import_params
[
:file
]
&&
import_params
[
:file
][
'tempfile'
].
respond_to?
(
:read
)
import_params
[
:file
]
&&
import_params
[
:file
][
'tempfile'
].
respond_to?
(
:read
)
end
end
def
validate_file!
render_api_error!
(
'The file is invalid'
,
400
)
unless
file_is_valid?
end
end
end
before
do
before
do
forbidden!
unless
Gitlab
::
CurrentSettings
.
import_sources
.
include?
(
'gitlab_project'
)
forbidden!
unless
Gitlab
::
CurrentSettings
.
import_sources
.
include?
(
'gitlab_project'
)
end
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
API
::
PROJECT_ENDPOINT_REQUIREMENTS
do
params
do
params
do
requires
:path
,
type:
String
,
desc:
'The new project path and name'
requires
:path
,
type:
String
,
desc:
'The new project path and name'
requires
:file
,
type:
File
,
desc:
'The project export file to be imported'
requires
:file
,
type:
File
,
desc:
'The project export file to be imported'
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
optional
:namespace
,
type:
String
,
desc:
'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
end
end
desc
'Create a new project import'
do
desc
'Create a new project import'
do
detail
'This feature was introduced in GitLab 10.6.'
success
Entities
::
ProjectImportStatus
success
Entities
::
ProjectImportStatus
end
end
post
'import'
do
post
'import'
do
...
@@ -30,13 +35,10 @@ module API
...
@@ -30,13 +35,10 @@ module API
Gitlab
::
QueryLimiting
.
whitelist
(
'https://gitlab.com/gitlab-org/gitlab-ce/issues/42437'
)
Gitlab
::
QueryLimiting
.
whitelist
(
'https://gitlab.com/gitlab-org/gitlab-ce/issues/42437'
)
namespace
=
import_params
[
:namespace
]
namespace
=
if
import_params
[
:namespace
]
namespace
=
if
namespace
.
blank?
find_namespace!
(
import_params
[
:namespace
])
current_user
.
namespace
elsif
namespace
=~
/^\d+$/
Namespace
.
find_by
(
id:
namespace
)
else
else
Namespace
.
find_by_path_or_name
(
namespace
)
current_user
.
namespace
end
end
project_params
=
import_params
.
merge
(
namespace_id:
namespace
.
id
,
project_params
=
import_params
.
merge
(
namespace_id:
namespace
.
id
,
...
@@ -52,6 +54,7 @@ module API
...
@@ -52,6 +54,7 @@ module API
requires
:id
,
type:
String
,
desc:
'The ID of a project'
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
end
desc
'Get a project export status'
do
desc
'Get a project export status'
do
detail
'This feature was introduced in GitLab 10.6.'
success
Entities
::
ProjectImportStatus
success
Entities
::
ProjectImportStatus
end
end
get
':id/import'
do
get
':id/import'
do
...
...
spec/requests/api/project_import_spec.rb
View file @
e613d777
...
@@ -17,8 +17,7 @@ describe API::ProjectImport do
...
@@ -17,8 +17,7 @@ describe API::ProjectImport do
describe
'POST /projects/import'
do
describe
'POST /projects/import'
do
it
'schedules an import using a namespace'
do
it
'schedules an import using a namespace'
do
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
stub_import
(
user
.
namespace
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
namespace
.
id
,
any_args
).
and_call_original
post
api
(
'/projects/import'
,
user
),
path:
'test-import'
,
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
id
post
api
(
'/projects/import'
,
user
),
path:
'test-import'
,
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
id
...
@@ -26,8 +25,7 @@ describe API::ProjectImport do
...
@@ -26,8 +25,7 @@ describe API::ProjectImport do
end
end
it
'schedules an import using the namespace path'
do
it
'schedules an import using the namespace path'
do
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
stub_import
(
unamespace
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
namespace
.
id
,
any_args
).
and_call_original
post
api
(
'/projects/import'
,
user
),
path:
'test-import'
,
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
full_path
post
api
(
'/projects/import'
,
user
),
path:
'test-import'
,
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
full_path
...
@@ -35,14 +33,23 @@ describe API::ProjectImport do
...
@@ -35,14 +33,23 @@ describe API::ProjectImport do
end
end
it
'schedules an import at the user namespace level'
do
it
'schedules an import at the user namespace level'
do
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
stub_import
(
user
.
namespace
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
user
.
namespace
.
id
,
any_args
).
and_call_original
post
api
(
'/projects/import'
,
user
),
path:
'test-import2'
,
file:
fixture_file_upload
(
file
)
post
api
(
'/projects/import'
,
user
),
path:
'test-import2'
,
file:
fixture_file_upload
(
file
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
end
end
it
'schedules an import at the user namespace level'
do
expect_any_instance_of
(
Project
).
not_to
receive
(
:import_schedule
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
not_to
receive
(
:new
)
post
api
(
'/projects/import'
,
user
),
namespace:
'nonexistent'
,
path:
'test-import2'
,
file:
fixture_file_upload
(
file
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Namespace Not Found'
)
end
it
'does not schedule an import if the user has no permission to the namespace'
do
it
'does not schedule an import if the user has no permission to the namespace'
do
expect_any_instance_of
(
Project
).
not_to
receive
(
:import_schedule
)
expect_any_instance_of
(
Project
).
not_to
receive
(
:import_schedule
)
...
@@ -51,8 +58,8 @@ describe API::ProjectImport do
...
@@ -51,8 +58,8 @@ describe API::ProjectImport do
file:
fixture_file_upload
(
file
),
file:
fixture_file_upload
(
file
),
namespace:
namespace
.
full_path
)
namespace:
namespace
.
full_path
)
expect
(
response
).
to
have_gitlab_http_status
(
40
0
)
expect
(
response
).
to
have_gitlab_http_status
(
40
4
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
Namespace is not vali
d'
)
expect
(
json_response
[
'message'
]).
to
eq
(
'
404 Namespace Not Foun
d'
)
end
end
it
'does not schedule an import if the user uploads no valid file'
do
it
'does not schedule an import if the user uploads no valid file'
do
...
@@ -63,6 +70,11 @@ describe API::ProjectImport do
...
@@ -63,6 +70,11 @@ describe API::ProjectImport do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'file is invalid'
)
expect
(
json_response
[
'error'
]).
to
eq
(
'file is invalid'
)
end
end
def
stub_import
(
namespace
)
expect_any_instance_of
(
Project
).
to
receive
(
:import_schedule
)
expect
(
Gitlab
::
ImportExport
::
ProjectCreator
).
to
receive
(
:new
).
with
(
namespace
.
id
,
any_args
).
and_call_original
end
end
end
describe
'GET /projects/:id/import'
do
describe
'GET /projects/:id/import'
do
...
...
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