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
91035871
Commit
91035871
authored
Aug 17, 2017
by
Felipe Artur
Committed by
Rémy Coutable
Aug 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix project import to group when there are project milestones
parent
3a395573
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
24 deletions
+139
-24
changelogs/unreleased/issue_35580.yml
changelogs/unreleased/issue_35580.yml
+4
-0
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+17
-4
spec/lib/gitlab/import_export/project.light.json
spec/lib/gitlab/import_export/project.light.json
+85
-15
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+33
-5
No files found.
changelogs/unreleased/issue_35580.yml
0 → 100644
View file @
91035871
---
title
:
Fix project milestones import when projects belongs to a group
merge_request
:
author
:
lib/gitlab/import_export/project_tree_restorer.rb
View file @
91035871
module
Gitlab
module
ImportExport
class
ProjectTreeRestorer
# Relations which cannot have both group_id and project_id at the same time
RESTRICT_PROJECT_AND_GROUP
=
%i(milestones)
.
freeze
def
initialize
(
user
:,
shared
:,
project
:)
@path
=
File
.
join
(
shared
.
export_path
,
'project.json'
)
@user
=
user
...
...
@@ -118,9 +121,11 @@ module Gitlab
end
def
create_relation
(
relation
,
relation_hash_list
)
relation_type
=
relation
.
to_sym
relation_array
=
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
relation_hash:
parsed_relation_hash
(
relation_hash
),
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
_type
,
relation_hash:
parsed_relation_hash
(
relation_hash
,
relation_type
),
members_mapper:
members_mapper
,
user:
@user
,
project:
restored_project
)
...
...
@@ -129,8 +134,16 @@ module Gitlab
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
end
def
parsed_relation_hash
(
relation_hash
)
relation_hash
.
merge!
(
'group_id'
=>
restored_project
.
group
.
try
(
:id
),
'project_id'
=>
restored_project
.
id
)
def
parsed_relation_hash
(
relation_hash
,
relation_type
)
if
RESTRICT_PROJECT_AND_GROUP
.
include?
(
relation_type
)
params
=
{}
params
[
'group_id'
]
=
restored_project
.
group
.
try
(
:id
)
if
relation_hash
[
'group_id'
]
params
[
'project_id'
]
=
restored_project
.
id
if
relation_hash
[
'project_id'
]
else
params
=
{
'group_id'
=>
restored_project
.
group
.
try
(
:id
),
'project_id'
=>
restored_project
.
id
}
end
relation_hash
.
merge
(
params
)
end
end
end
...
...
spec/lib/gitlab/import_export/project.light.json
View file @
91035871
...
...
@@ -2,6 +2,20 @@
"description"
:
"Nisi et repellendus ut enim quo accusamus vel magnam."
,
"visibility_level"
:
10
,
"archived"
:
false
,
"milestones"
:
[
{
"id"
:
1
,
"title"
:
"test milestone"
,
"project_id"
:
8
,
"description"
:
"test milestone"
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"updated_at"
:
"2016-06-14T15:02:04.415Z"
,
"state"
:
"active"
,
"iid"
:
1
,
"group_id"
:
null
}
],
"labels"
:
[
{
"id"
:
2
,
...
...
@@ -13,20 +27,6 @@
"template"
:
false
,
"description"
:
""
,
"type"
:
"ProjectLabel"
,
"priorities"
:
[
]
},
{
"id"
:
3
,
"title"
:
"test3"
,
"color"
:
"#428bca"
,
"group_id"
:
8
,
"created_at"
:
"2016-07-22T08:55:44.161Z"
,
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"template"
:
false
,
"description"
:
""
,
"project_id"
:
null
,
"type"
:
"GroupLabel"
,
"priorities"
:
[
{
"id"
:
1
,
...
...
@@ -39,6 +39,76 @@
]
}
],
"issues"
:
[
{
"id"
:
1
,
"title"
:
"Fugiat est minima quae maxime non similique."
,
"assignee_id"
:
null
,
"project_id"
:
8
,
"author_id"
:
1
,
"created_at"
:
"2017-07-07T18:13:01.138Z"
,
"updated_at"
:
"2017-08-15T18:37:40.807Z"
,
"branch_name"
:
null
,
"description"
:
"Quam totam fuga numquam in eveniet."
,
"state"
:
"opened"
,
"iid"
:
20
,
"updated_by_id"
:
1
,
"confidential"
:
false
,
"deleted_at"
:
null
,
"due_date"
:
null
,
"moved_to_id"
:
null
,
"lock_version"
:
null
,
"time_estimate"
:
0
,
"closed_at"
:
null
,
"last_edited_at"
:
null
,
"last_edited_by_id"
:
null
,
"group_milestone_id"
:
null
,
"label_links"
:
[
{
"id"
:
11
,
"label_id"
:
6
,
"target_id"
:
1
,
"target_type"
:
"Issue"
,
"created_at"
:
"2017-08-15T18:37:40.795Z"
,
"updated_at"
:
"2017-08-15T18:37:40.795Z"
,
"label"
:
{
"id"
:
6
,
"title"
:
"group label"
,
"color"
:
"#A8D695"
,
"project_id"
:
null
,
"created_at"
:
"2017-08-15T18:37:19.698Z"
,
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"template"
:
false
,
"description"
:
""
,
"group_id"
:
5
,
"type"
:
"GroupLabel"
,
"priorities"
:
[]
}
},
{
"id"
:
11
,
"label_id"
:
2
,
"target_id"
:
1
,
"target_type"
:
"Issue"
,
"created_at"
:
"2017-08-15T18:37:40.795Z"
,
"updated_at"
:
"2017-08-15T18:37:40.795Z"
,
"label"
:
{
"id"
:
6
,
"title"
:
"project label"
,
"color"
:
"#A8D695"
,
"project_id"
:
null
,
"created_at"
:
"2017-08-15T18:37:19.698Z"
,
"updated_at"
:
"2017-08-15T18:37:19.698Z"
,
"template"
:
false
,
"description"
:
""
,
"group_id"
:
5
,
"type"
:
"ProjectLabel"
,
"priorities"
:
[]
}
}
]
}
],
"snippets"
:
[
],
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
91035871
...
...
@@ -183,7 +183,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
before
do
allow
(
ImportExport
).
to
receive
(
:project_filename
).
and_return
(
'project.light.json'
)
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.light.json"
)
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/lib/gitlab/import_export/'
)
end
...
...
@@ -195,7 +196,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
restored_project_json
expect
(
shared
.
errors
.
first
).
not_to
include
(
'test'
)
expect
(
shared
.
errors
.
first
).
to
be_nil
end
end
end
...
...
@@ -219,15 +220,42 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.light.json"
)
restored_project_json
end
it
'has group labels'
do
expect
(
GroupLabel
.
count
).
to
eq
(
1
)
it
'correctly restores project'
do
expect
(
restored_project_json
).
to
be_truthy
expect
(
shared
.
errors
).
to
be_empty
end
it
'has labels'
do
expect
(
project
.
labels
.
count
).
to
eq
(
2
)
end
it
'creates group label'
do
expect
(
project
.
group
.
labels
.
count
).
to
eq
(
1
)
end
it
'has label priorities'
do
expect
(
GroupLabel
.
first
.
priorities
).
not_to
be_empty
expect
(
project
.
labels
.
first
.
priorities
).
not_to
be_empty
end
it
'has milestones'
do
expect
(
project
.
milestones
.
count
).
to
eq
(
1
)
end
it
'has issue'
do
expect
(
project
.
issues
.
count
).
to
eq
(
1
)
expect
(
project
.
issues
.
first
.
labels
.
count
).
to
eq
(
2
)
end
it
'has issue with group label and project label'
do
labels
=
project
.
issues
.
first
.
labels
expect
(
labels
.
where
(
type:
"GroupLabel"
).
count
).
to
eq
(
1
)
expect
(
labels
.
where
(
type:
"ProjectLabel"
).
count
).
to
eq
(
1
)
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