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
8522173e
Commit
8522173e
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
cc061cd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
42 deletions
+47
-42
lib/gitlab/import_export/group_project_finder.rb
lib/gitlab/import_export/group_project_finder.rb
+27
-2
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+6
-26
spec/lib/gitlab/import_export/group_project_finder_spec.rb
spec/lib/gitlab/import_export/group_project_finder_spec.rb
+14
-14
No files found.
lib/gitlab/import_export/group_project_finder.rb
View file @
8522173e
...
@@ -31,7 +31,9 @@ module Gitlab
...
@@ -31,7 +31,9 @@ module Gitlab
private
private
def
where_clause
def
where_clause
@attributes
.
except
(
:group
,
:project
).
map
do
|
key
,
value
|
return
{
project_id:
@project
.
id
}
unless
milestone?
||
label?
@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
...
@@ -48,13 +50,36 @@ module Gitlab
...
@@ -48,13 +50,36 @@ module Gitlab
def
project_attributes
def
project_attributes
@attributes
.
except
(
:group
).
tap
do
|
atts
|
@attributes
.
except
(
:group
).
tap
do
|
atts
|
atts
[
'type'
]
=
'ProjectLabel'
if
label?
if
label?
atts
[
'type'
]
=
'ProjectLabel'
elsif
milestone?
if
atts
[
'group_id'
]
atts
[
'iid'
]
=
nil
atts
.
delete
(
'group_id'
)
else
claim_iid
end
end
end
end
end
end
def
label?
def
label?
@klass
==
Label
||
@klass
<
Label
@klass
==
Label
||
@klass
<
Label
end
end
def
milestone?
@klass
==
Milestone
end
def
claim_iid
group_milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
group_milestone
.
update!
(
iid:
max_milestone_iid
+
1
)
if
group_milestone
end
def
max_milestone_iid
[
@attributes
[
'iid'
],
@project
.
milestones
.
maximum
(
:iid
)].
compact
.
max
end
end
end
end
end
end
end
lib/gitlab/import_export/relation_factory.rb
View file @
8522173e
...
@@ -257,15 +257,7 @@ module Gitlab
...
@@ -257,15 +257,7 @@ module Gitlab
end
end
def
existing_object
def
existing_object
@existing_object
||=
@existing_object
||=
find_or_create_object!
begin
existing_object
=
find_or_create_object!
# Done in two steps, as MySQL behaves differently than PostgreSQL using
# the +find_or_create_by+ method and does not return the ID the second time.
existing_object
.
update!
(
parsed_relation_hash
)
existing_object
end
end
end
def
unknown_service?
def
unknown_service?
...
@@ -275,29 +267,17 @@ module Gitlab
...
@@ -275,29 +267,17 @@ module Gitlab
def
find_or_create_object!
def
find_or_create_object!
# Can't use IDs as validation exists calilng `.group` or `.project`
# Can't use IDs as validation exists calilng `.group` or `.project`
finder_hash
=
{
project:
@project
}
.
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
[
:title
]
=
parsed_relation_hash
[
'title'
]
if
parsed_relation_hash
[
'title'
]
hash
[
:title
]
=
parsed_relation_hash
[
'title'
]
if
parsed_relation_hash
[
'title'
]
hash
.
delete
(
'project_id'
)
end
end
if
label?
if
label?
label
=
GroupProjectFinder
.
find_or_new
(
Label
,
finder_hash
)
GroupProjectFinder
.
find_or_new
(
Label
,
finder_hash
)
parsed_relation_hash
.
delete
(
'priorities'
)
if
label
.
persisted?
parsed_relation_hash
.
delete
(
'type'
)
label
.
save!
label
else
else
object
=
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
if
milestone?
parsed_relation_hash
.
delete
(
'group_id'
)
if
object
.
project
parsed_relation_hash
.
delete
(
'project_id'
)
if
object
.
group
parsed_relation_hash
.
delete
(
'iid'
)
parsed_relation_hash
.
delete
(
'id'
)
end
object
end
end
end
end
...
...
spec/lib/gitlab/import_export/group_project_finder_spec.rb
View file @
8522173e
...
@@ -16,15 +16,15 @@ describe Gitlab::ImportExport::GroupProjectFinder do
...
@@ -16,15 +16,15 @@ describe Gitlab::ImportExport::GroupProjectFinder do
expect
(
described_class
.
find_or_new
(
Label
,
expect
(
described_class
.
find_or_new
(
Label
,
title:
'group label'
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)).
to
eq
(
group_label
)
group:
project
.
group
)).
to
eq
(
group_label
)
end
end
it
'initializes a new label'
do
it
'initializes a new label'
do
label
=
described_class
.
find_or_new
(
Label
,
label
=
described_class
.
find_or_new
(
Label
,
title:
'group label'
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)
group:
project
.
group
)
expect
(
label
.
persisted?
).
to
be
false
expect
(
label
.
persisted?
).
to
be
false
end
end
...
@@ -32,8 +32,8 @@ describe Gitlab::ImportExport::GroupProjectFinder do
...
@@ -32,8 +32,8 @@ describe Gitlab::ImportExport::GroupProjectFinder do
it
'creates a new label'
do
it
'creates a new label'
do
label
=
described_class
.
find_or_create
(
Label
,
label
=
described_class
.
find_or_create
(
Label
,
title:
'group label'
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)
group:
project
.
group
)
expect
(
label
.
persisted?
).
to
be
true
expect
(
label
.
persisted?
).
to
be
true
end
end
...
@@ -45,24 +45,24 @@ describe Gitlab::ImportExport::GroupProjectFinder do
...
@@ -45,24 +45,24 @@ describe Gitlab::ImportExport::GroupProjectFinder do
expect
(
described_class
.
find_or_new
(
Milestone
,
expect
(
described_class
.
find_or_new
(
Milestone
,
title:
'group milestone'
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)).
to
eq
(
milestone
)
group:
project
.
group
)).
to
eq
(
milestone
)
end
end
it
'initializes a new milestone'
do
it
'initializes a new milestone'
do
milestone
=
described_class
.
find_or_new
(
Milestone
,
milestone
=
described_class
.
find_or_new
(
Milestone
,
title:
'group milestone'
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)
group:
project
.
group
)
expect
(
milestone
.
persisted?
).
to
be
false
expect
(
milestone
.
persisted?
).
to
be
false
end
end
it
'creates a new milestone'
do
it
'creates a new milestone'
do
milestone
=
described_class
.
find_or_create
(
Milestone
,
milestone
=
described_class
.
find_or_create
(
Milestone
,
title:
'group milestone'
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
project:
project
,
'group_id'
=>
project
.
group
.
id
)
group:
project
.
group
)
expect
(
milestone
.
persisted?
).
to
be
true
expect
(
milestone
.
persisted?
).
to
be
true
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