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
iv
gitlab-ce
Commits
903da377
Commit
903da377
authored
Jun 13, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - starting refactoring import/export to use services
parent
f449eeb6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
8 deletions
+55
-8
app/controllers/import/gitlab_projects_controller.rb
app/controllers/import/gitlab_projects_controller.rb
+21
-4
app/views/import/gitlab_projects/new.html.haml
app/views/import/gitlab_projects/new.html.haml
+4
-1
app/views/import/gitlab_projects/status.html.haml
app/views/import/gitlab_projects/status.html.haml
+0
-0
lib/gitlab/gitlab_import/project_creator.rb
lib/gitlab/gitlab_import/project_creator.rb
+1
-3
lib/gitlab/import_export/project_creator.rb
lib/gitlab/import_export/project_creator.rb
+29
-0
No files found.
app/controllers/import/gitlab_projects_controller.rb
View file @
903da377
...
@@ -2,24 +2,41 @@ class Import::GitlabProjectsController < Import::BaseController
...
@@ -2,24 +2,41 @@ class Import::GitlabProjectsController < Import::BaseController
before_action
:verify_gitlab_project_import_enabled
before_action
:verify_gitlab_project_import_enabled
before_action
:verify_project_and_namespace_access
before_action
:verify_project_and_namespace_access
rescue_from
OAuth
::
Error
,
with: :gitlab_project_unauthorized
def
new
def
new
@namespace_id
=
project_params
[
:namespace_id
]
@namespace_id
=
project_params
[
:namespace_id
]
@path
=
project_params
[
:path
]
@path
=
project_params
[
:path
]
end
end
def
create
def
create
unless
file_is_valid?
return
redirect_back_or_default
(
options:
{
alert:
"You need to upload a GitLab project export archive."
})
end
@project
=
Project
.
create_from_import_job
(
current_user_id:
current_user
.
id
,
@project
=
Project
.
create_from_import_job
(
current_user_id:
current_user
.
id
,
tmp_file:
File
.
expand_path
(
params
[
:file
].
path
),
tmp_file:
File
.
expand_path
(
params
[
:file
].
path
),
namespace_id:
project_params
[
:namespace_id
],
namespace_id:
project_params
[
:namespace_id
],
project_path:
project_params
[
:path
])
project_path:
project_params
[
:path
])
redirect_to
dashboard_projects_path
@project
=
Gitlab
::
GitlabImport
::
ProjectCreator
.
new
(
repo
,
namespace
,
current_user
,
access_params
).
execute
flash
[
:notice
]
=
"The project import has been started."
if
@project
.
saved?
redirect_to
(
project_path
(
@project
),
notice:
"Project '
#{
@project
.
name
}
' is being imported."
)
else
render
'new'
end
end
end
private
private
def
file_is_valid?
params
[
:file
].
respond_to?
(
:read
)
&&
params
[
:file
].
content_type
==
'application/x-gzip'
end
def
verify_project_and_namespace_access
def
verify_project_and_namespace_access
unless
namespace_access?
unless
namespace_access?
render_403
render_403
...
@@ -27,7 +44,7 @@ class Import::GitlabProjectsController < Import::BaseController
...
@@ -27,7 +44,7 @@ class Import::GitlabProjectsController < Import::BaseController
end
end
def
namespace_access?
def
namespace_access?
c
urrent_user
.
can?
(
:create_projects
,
Namespace
.
find
(
project_params
[
:namespace_id
]))
c
an?
(
current_user
,
:create_projects
,
Namespace
.
find
(
project_params
[
:namespace_id
]))
end
end
def
verify_gitlab_project_import_enabled
def
verify_gitlab_project_import_enabled
...
...
app/views/import/gitlab_projects/new.html.haml
View file @
903da377
-
page_title
"GitLab Import"
-
page_title
"GitLab Import"
-
header_title
"Projects"
,
root_path
-
header_title
"Projects"
,
root_path
%h3
.page-title
%h3
.page-title
%i
.fa.fa-gitlab
=
icon
(
'gitlab'
)
Import projects from GitLab
Import projects from GitLab
%hr
%hr
=
form_tag
import_gitlab_project_path
,
class:
'form-horizontal'
,
multipart:
true
do
=
form_tag
import_gitlab_project_path
,
class:
'form-horizontal'
,
multipart:
true
do
%p
Project will be imported to path
#{
@path
}
%p
%p
To get started add your exported project file below:
To get started add your exported project file below:
.form-group
.form-group
...
...
app/views/import/gitlab_projects/status.html.haml
deleted
100644 → 0
View file @
f449eeb6
lib/gitlab/gitlab_import/project_creator.rb
View file @
903da377
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
end
end
def
execute
def
execute
project
=
::
Projects
::
CreateService
.
new
(
::
Projects
::
CreateService
.
new
(
current_user
,
current_user
,
name:
repo
[
"name"
],
name:
repo
[
"name"
],
path:
repo
[
"path"
],
path:
repo
[
"path"
],
...
@@ -22,8 +22,6 @@ module Gitlab
...
@@ -22,8 +22,6 @@ module Gitlab
import_source:
repo
[
"path_with_namespace"
],
import_source:
repo
[
"path_with_namespace"
],
import_url:
repo
[
"http_url_to_repo"
].
sub
(
"://"
,
"://oauth2:
#{
@session_data
[
:gitlab_access_token
]
}
@"
)
import_url:
repo
[
"http_url_to_repo"
].
sub
(
"://"
,
"://oauth2:
#{
@session_data
[
:gitlab_access_token
]
}
@"
)
).
execute
).
execute
project
end
end
end
end
end
end
...
...
lib/gitlab/import_export/project_creator.rb
0 → 100644
View file @
903da377
module
Gitlab
module
ImportExport
class
ProjectCreator
def
initialize
(
namespace_id
,
current_user
,
)
@repo
=
repo
@namespace
=
Namespace
.
find_by_id
(
namespace_id
)
@current_user
=
current_user
@user_map
=
user_map
end
def
execute
::
Projects
::
CreateService
.
new
(
current_user
,
name:
repo
.
name
,
path:
repo
.
name
,
description:
repo
.
summary
,
namespace:
namespace
,
creator:
current_user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
,
import_type:
"google_code"
,
import_source:
repo
.
name
,
import_url:
repo
.
import_url
,
import_data:
{
data:
{
'repo'
=>
repo
.
raw_data
,
'user_map'
=>
user_map
}
}
).
execute
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