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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
68f8ae26
Commit
68f8ae26
authored
Jul 05, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve manifest import logic
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
237a3597
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
28 deletions
+41
-28
app/controllers/import/manifest_controller.rb
app/controllers/import/manifest_controller.rb
+27
-15
app/views/import/manifest/new.html.haml
app/views/import/manifest/new.html.haml
+2
-3
app/views/import/manifest/status.html.haml
app/views/import/manifest/status.html.haml
+11
-9
lib/gitlab/manifest_import/importer.rb
lib/gitlab/manifest_import/importer.rb
+1
-1
No files found.
app/controllers/import/manifest_controller.rb
View file @
68f8ae26
class
Import::ManifestController
<
Import
::
BaseController
class
Import::ManifestController
<
Import
::
BaseController
before_action
:ensure_session
,
only:
[
:create
,
:status
,
:jobs
]
before_action
:ensure_import_vars
,
only:
[
:create
,
:status
]
before_action
:group
,
only:
[
:status
,
:create
]
def
new
def
new
end
end
def
status
def
status
@repos
=
session
[
:projects
]
@already_added_projects
=
find_already_added_projects
already_added_import_urls
=
@already_added_projects
.
pluck
(
:import_url
)
@already_added_projects
=
find_already_added_projects
(
'manifest'
).
where
(
namespace_id:
group
)
@pending_repositories
=
repositories
.
to_a
.
reject
do
|
repository
|
already_added_projects_names
=
@already_added_projects
.
pluck
(
:import_url
)
already_added_import_urls
.
include?
(
repository
[
:url
])
end
@repos
=
@repos
.
to_a
.
reject
{
|
repo
|
already_added_projects_names
.
include?
repo
[
:url
]
}
end
end
def
upload
def
upload
...
@@ -26,11 +25,9 @@ class Import::ManifestController < Import::BaseController
...
@@ -26,11 +25,9 @@ class Import::ManifestController < Import::BaseController
manifest
=
Gitlab
::
ManifestImport
::
Manifest
.
new
(
params
[
:manifest
].
tempfile
)
manifest
=
Gitlab
::
ManifestImport
::
Manifest
.
new
(
params
[
:manifest
].
tempfile
)
if
manifest
.
valid?
if
manifest
.
valid?
session
[
:
project
s
]
=
manifest
.
projects
session
[
:
repositorie
s
]
=
manifest
.
projects
session
[
:group_id
]
=
group
.
id
session
[
:group_id
]
=
group
.
id
flash
[
:notice
]
=
"Import successfully started."
redirect_to
status_import_manifest_path
redirect_to
status_import_manifest_path
else
else
@errors
=
manifest
.
errors
@errors
=
manifest
.
errors
...
@@ -40,11 +37,11 @@ class Import::ManifestController < Import::BaseController
...
@@ -40,11 +37,11 @@ class Import::ManifestController < Import::BaseController
end
end
def
jobs
def
jobs
render
json:
find_jobs
(
'manifest'
)
render
json:
find_jobs
end
end
def
create
def
create
repository
=
session
[
:projects
]
.
find
do
|
project
|
repository
=
repositories
.
find
do
|
project
|
project
[
:id
]
==
params
[
:repo_id
].
to_i
project
[
:id
]
==
params
[
:repo_id
].
to_i
end
end
...
@@ -59,13 +56,28 @@ class Import::ManifestController < Import::BaseController
...
@@ -59,13 +56,28 @@ class Import::ManifestController < Import::BaseController
private
private
def
ensure_
session
def
ensure_
import_vars
if
session
[
:projects
].
blank?
||
session
[
:group_id
].
blank
?
unless
group
&&
repositories
.
present
?
redirect_to
(
new_import_manifest_path
)
redirect_to
(
new_import_manifest_path
)
end
end
end
end
def
group
def
group
@group
||=
Group
.
find
(
session
[
:group_id
])
@group
||=
Group
.
find_by
(
id:
session
[
:group_id
])
end
def
repositories
@repositories
||=
session
[
:repositories
]
end
def
find_jobs
find_already_added_projects
.
to_json
(
only:
[
:id
],
methods:
[
:import_status
])
end
def
find_already_added_projects
group
.
all_projects
.
where
(
import_type:
'manifest'
)
.
where
(
creator_id:
current_user
)
.
includes
(
:import_state
)
end
end
end
end
app/views/import/manifest/new.html.haml
View file @
68f8ae26
-
page_title
"Manifest
I
mport"
-
page_title
"Manifest
file i
mport"
-
header_title
"Projects"
,
root_path
-
header_title
"Projects"
,
root_path
%h3
.page-title
%h3
.page-title
=
icon
(
'git'
)
=
_
(
'Manifest file import'
)
Import multiple repositories
-
if
@errors
.
present?
-
if
@errors
.
present?
.alert.alert-danger
.alert.alert-danger
...
...
app/views/import/manifest/status.html.haml
View file @
68f8ae26
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
-
provider
=
'manifest'
-
provider
=
'manifest'
%h3
.page-title
%h3
.page-title
=
icon
(
'git'
)
=
_
(
'Manifest file import'
)
=
_
(
'Import multiple repositories'
)
%p
.light
=
_
(
'Import multiple repositories by uploading a manifest file.'
)
%p
%p
=
button_tag
class:
"btn btn-import btn-success js-import-all"
do
=
button_tag
class:
"btn btn-import btn-success js-import-all"
do
...
@@ -24,10 +26,10 @@
...
@@ -24,10 +26,10 @@
%tbody
%tbody
-
@already_added_projects
.
each
do
|
project
|
-
@already_added_projects
.
each
do
|
project
|
%tr
{
id:
"project_#{project.id}"
,
class:
"#{project_status_css_class(project.import_status)}"
}
%tr
{
id:
"project_#{project.id}"
,
class:
"#{project_status_css_class(project.import_status)}"
}
%td
=
link_to_project
project
%td
%td
=
project
.
import_url
=
project
.
import_url
%td
=
link_to_project
project
%td
.job-status
%td
.job-status
-
if
project
.
import_status
==
'finished'
-
if
project
.
import_status
==
'finished'
%span
%span
...
@@ -41,15 +43,15 @@
...
@@ -41,15 +43,15 @@
-
else
-
else
=
project
.
human_import_status_name
=
project
.
human_import_status_name
-
@
repos
.
each
do
|
repo
|
-
@
pending_repositories
.
each
do
|
repository
|
%tr
{
id:
"repo_#{repo[:id]}"
}
%tr
{
id:
"repo_#{repo
sitory
[:id]}"
}
%td
%td
=
repo
[
:url
]
=
repo
sitory
[
:url
]
%td
.import-target
%td
.import-target
=
import_project_target
(
@group
.
path
,
repo
[
:path
])
=
import_project_target
(
@group
.
full_path
,
repository
[
:path
])
%td
.import-actions.job-status
%td
.import-actions.job-status
=
button_tag
class:
"btn btn-import js-add-to-import"
do
=
button_tag
class:
"btn btn-import js-add-to-import"
do
Import
=
_
(
'Import'
)
=
icon
(
"spinner spin"
,
class:
"loading-icon"
)
=
icon
(
"spinner spin"
,
class:
"loading-icon"
)
.js-importer-status
{
data:
{
jobs_import_path:
"#{url_for([:jobs, :import, provider])}"
,
.js-importer-status
{
data:
{
jobs_import_path:
"#{url_for([:jobs, :import, provider])}"
,
...
...
lib/gitlab/manifest_import/importer.rb
View file @
68f8ae26
...
@@ -17,7 +17,7 @@ module Gitlab
...
@@ -17,7 +17,7 @@ module Gitlab
def
import_project
def
import_project
group_full_path
,
_
,
project_path
=
repository
[
:path
].
rpartition
(
'/'
)
group_full_path
,
_
,
project_path
=
repository
[
:path
].
rpartition
(
'/'
)
group_full_path
=
File
.
join
(
destination
.
path
,
group_full_path
)
if
destination
group_full_path
=
File
.
join
(
destination
.
full_
path
,
group_full_path
)
if
destination
group
=
Group
.
find_by_full_path
(
group_full_path
)
||
group
=
Group
.
find_by_full_path
(
group_full_path
)
||
create_group_with_parents
(
group_full_path
)
create_group_with_parents
(
group_full_path
)
...
...
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