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
Jérome Perrin
gitlab-ce
Commits
35d69ccf
Commit
35d69ccf
authored
Jun 22, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more specs and refactor more relation factory code
parent
3d3e441c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
9 deletions
+118
-9
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+1
-7
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+10
-2
spec/lib/gitlab/import_export/project.milestone-iid.json
spec/lib/gitlab/import_export/project.milestone-iid.json
+80
-0
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+27
-0
No files found.
lib/gitlab/import_export/project_tree_restorer.rb
View file @
35d69ccf
...
...
@@ -178,7 +178,7 @@ module Gitlab
def
create_relation
(
relation
,
relation_hash_list
)
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
,
relation
.
to_sym
)
,
relation_hash:
relation_hash
,
members_mapper:
members_mapper
,
user:
@user
,
project:
@restored_project
,
...
...
@@ -188,12 +188,6 @@ module Gitlab
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
end
def
parsed_relation_hash
(
relation_hash
,
relation_type
)
params
=
{
'group_id'
=>
restored_project
.
group
.
try
(
:id
),
'project_id'
=>
restored_project
.
id
}
relation_hash
.
merge
(
params
)
end
def
reader
@reader
||=
Gitlab
::
ImportExport
::
Reader
.
new
(
shared:
@shared
)
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
35d69ccf
...
...
@@ -54,6 +54,8 @@ module Gitlab
@project
=
project
@imported_object_retries
=
0
@relation_hash
[
'project_id'
]
=
@project
.
id
# Remove excluded keys from relation_hash
# We don't do this in the parsed_relation_hash because of the 'transformed attributes'
# For example, MergeRequestDiffFiles exports its diff attribute as utf8_diff. Then,
...
...
@@ -81,12 +83,11 @@ module Gitlab
when
:merge_request_diff_files
then
setup_diff
when
:notes
then
setup_note
when
'Ci::Pipeline'
then
setup_pipeline
else
@relation_hash
[
'project_id'
]
=
@project
.
id
end
update_user_references
update_project_references
update_group_references
remove_duplicate_assignees
reset_tokens!
...
...
@@ -161,6 +162,13 @@ module Gitlab
@relation_hash
[
'target_project_id'
]
=
project_id
if
@relation_hash
[
'target_project_id'
]
end
def
update_group_references
return
unless
EXISTING_OBJECT_CHECK
.
include?
(
@relation_name
)
return
unless
@relation_hash
[
'group_id'
]
@relation_hash
[
'group_id'
]
=
@project
.
group
&
.
id
end
def
same_source_and_target?
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
...
...
spec/lib/gitlab/import_export/project.milestone-iid.json
0 → 100644
View file @
35d69ccf
{
"description"
:
"Nisi et repellendus ut enim quo accusamus vel magnam."
,
"import_type"
:
"gitlab_project"
,
"creator_id"
:
123
,
"visibility_level"
:
10
,
"archived"
:
false
,
"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
,
"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
,
"milestone"
:
{
"id"
:
1
,
"title"
:
"Group-level milestone"
,
"description"
:
"Group-level 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"
:
8
}
},
{
"id"
:
2
,
"title"
:
"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"
:
21
,
"updated_by_id"
:
1
,
"confidential"
:
false
,
"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
,
"milestone"
:
{
"id"
:
2
,
"title"
:
"Another milestone"
,
"project_id"
:
8
,
"description"
:
"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
}
}
],
"snippets"
:
[],
"hooks"
:
[]
}
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
35d69ccf
...
...
@@ -391,5 +391,32 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect
(
project
.
milestones
.
count
).
to
eq
(
0
)
end
end
context
'with clashing milestones on IID'
do
let!
(
:project
)
do
create
(
:project
,
:builds_disabled
,
:issues_disabled
,
name:
'project'
,
path:
'project'
,
group:
create
(
:group
))
end
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/lib/gitlab/import_export/project.milestone-iid.json"
)
end
it
'preserves the project milestone IID'
do
create
(
:milestone
,
name:
'A milestone'
,
group:
project
.
group
)
expect_any_instance_of
(
Gitlab
::
ImportExport
::
Shared
).
not_to
receive
(
:error
)
restored_project_json
expect
(
project
.
milestones
.
count
).
to
eq
(
2
)
expect
(
Milestone
.
find_by_title
(
'Another milestone'
).
iid
).
to
eq
(
1
)
expect
(
Milestone
.
find_by_title
(
'Group-level milestone'
).
iid
).
to
eq
(
2
)
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