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
Boxiang Sun
gitlab-ce
Commits
b0ddc55d
Commit
b0ddc55d
authored
Jun 20, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code once again to fix IID issues
parent
8522173e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
28 deletions
+13
-28
lib/gitlab/import_export/group_project_finder.rb
lib/gitlab/import_export/group_project_finder.rb
+10
-5
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+2
-22
spec/lib/gitlab/import_export/project.light.json
spec/lib/gitlab/import_export/project.light.json
+1
-1
No files found.
lib/gitlab/import_export/group_project_finder.rb
View file @
b0ddc55d
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
end
end
def
initialize
(
klass
,
attributes
)
def
initialize
(
klass
,
attributes
)
@klass
=
klass
@klass
=
klass
<
Label
?
Label
:
klass
@attributes
=
attributes
@attributes
=
attributes
@group
=
@attributes
[
:group
]
@group
=
@attributes
[
:group
]
@project
=
@attributes
[
:project
]
@project
=
@attributes
[
:project
]
...
@@ -33,7 +33,7 @@ module Gitlab
...
@@ -33,7 +33,7 @@ module Gitlab
def
where_clause
def
where_clause
return
{
project_id:
@project
.
id
}
unless
milestone?
||
label?
return
{
project_id:
@project
.
id
}
unless
milestone?
||
label?
@attributes
.
slice
(
:title
).
map
do
|
key
,
value
|
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
project_clause
=
table
[
key
].
eq
(
value
).
and
(
table
[
:project_id
].
eq
(
@project
.
id
))
project_clause
=
table
[
key
].
eq
(
value
).
and
(
table
[
:project_id
].
eq
(
@project
.
id
))
if
@group
if
@group
...
@@ -51,9 +51,9 @@ module Gitlab
...
@@ -51,9 +51,9 @@ module Gitlab
def
project_attributes
def
project_attributes
@attributes
.
except
(
:group
).
tap
do
|
atts
|
@attributes
.
except
(
:group
).
tap
do
|
atts
|
if
label?
if
label?
atts
[
'type'
]
=
'ProjectLabel'
atts
[
'type'
]
=
'ProjectLabel'
# Always create project labels
elsif
milestone?
elsif
milestone?
if
atts
[
'group_id'
]
if
atts
[
'group_id'
]
# Transform new group milestones into project ones
atts
[
'iid'
]
=
nil
atts
[
'iid'
]
=
nil
atts
.
delete
(
'group_id'
)
atts
.
delete
(
'group_id'
)
else
else
...
@@ -64,13 +64,18 @@ module Gitlab
...
@@ -64,13 +64,18 @@ module Gitlab
end
end
def
label?
def
label?
@klass
==
Label
||
@klass
<
Label
@klass
==
Label
end
end
def
milestone?
def
milestone?
@klass
==
Milestone
@klass
==
Milestone
end
end
# If an existing group milesone used the IIID
# claim the IID back and set the group milestone to use one available
# This is neccessary to fix situations like the following:
# - Importing into a user namespace project with exported group milestones
# where the IID of the Group milestone could conflict with a project one.
def
claim_iid
def
claim_iid
group_milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
group_milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
b0ddc55d
...
@@ -80,7 +80,6 @@ module Gitlab
...
@@ -80,7 +80,6 @@ module Gitlab
case
@relation_name
case
@relation_name
when
:merge_request_diff_files
then
setup_diff
when
:merge_request_diff_files
then
setup_diff
when
:notes
then
setup_note
when
:notes
then
setup_note
when
*
(
EXISTING_OBJECT_CHECK
-
[
:project_feature
])
then
setup_project_group
when
'Ci::Pipeline'
then
setup_pipeline
when
'Ci::Pipeline'
then
setup_pipeline
else
else
@relation_hash
[
'project_id'
]
=
@project
.
id
@relation_hash
[
'project_id'
]
=
@project
.
id
...
@@ -166,12 +165,6 @@ module Gitlab
...
@@ -166,12 +165,6 @@ module Gitlab
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
end
def
setup_project_group
@relation_hash
[
'project_id'
]
=
@project
.
id
@relation_hash
[
'group_id'
]
=
@project
.
group
&
.
id
@relation_hash
.
delete
(
'type'
)
end
def
reset_tokens!
def
reset_tokens!
return
unless
Gitlab
::
ImportExport
.
reset_tokens?
&&
TOKEN_RESET_MODELS
.
include?
(
@relation_name
.
to_s
)
return
unless
Gitlab
::
ImportExport
.
reset_tokens?
&&
TOKEN_RESET_MODELS
.
include?
(
@relation_name
.
to_s
)
...
@@ -266,27 +259,14 @@ module Gitlab
...
@@ -266,27 +259,14 @@ module Gitlab
end
end
def
find_or_create_object!
def
find_or_create_object!
# Can't use IDs as validation exists cal
ilng `.group` or `.project`
# Can't use IDs as validation exists cal
ling `group` or `project` attributes
finder_hash
=
parsed_relation_hash
.
tap
do
|
hash
|
finder_hash
=
parsed_relation_hash
.
tap
do
|
hash
|
hash
[
:group
]
=
@project
.
group
if
relation_class
.
attribute_method?
(
'group_id'
)
hash
[
:group
]
=
@project
.
group
if
relation_class
.
attribute_method?
(
'group_id'
)
hash
[
:project
]
=
@project
hash
[
:project
]
=
@project
hash
[
:title
]
=
parsed_relation_hash
[
'title'
]
if
parsed_relation_hash
[
'title'
]
hash
.
delete
(
'project_id'
)
hash
.
delete
(
'project_id'
)
end
end
if
label?
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
GroupProjectFinder
.
find_or_new
(
Label
,
finder_hash
)
else
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
end
end
def
label?
@relation_name
.
to_s
.
include?
(
'label'
)
end
def
milestone?
@relation_name
.
to_s
.
include?
(
'milestone'
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/import_export/project.light.json
View file @
b0ddc55d
...
@@ -67,7 +67,7 @@
...
@@ -67,7 +67,7 @@
"milestone"
:
{
"milestone"
:
{
"id"
:
1
,
"id"
:
1
,
"title"
:
"A milestone"
,
"title"
:
"A milestone"
,
"
project
_id"
:
8
,
"
group
_id"
:
8
,
"description"
:
"Project-level milestone"
,
"description"
:
"Project-level milestone"
,
"due_date"
:
null
,
"due_date"
:
null
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
"created_at"
:
"2016-06-14T15:02:04.415Z"
,
...
...
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