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
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
Show 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
private
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
))
if
@group
...
...
@@ -48,13 +50,36 @@ module Gitlab
def
project_attributes
@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
def
label?
@klass
==
Label
||
@klass
<
Label
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
lib/gitlab/import_export/relation_factory.rb
View file @
8522173e
...
...
@@ -257,15 +257,7 @@ module Gitlab
end
def
existing_object
@existing_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
@existing_object
||=
find_or_create_object!
end
def
unknown_service?
...
...
@@ -275,29 +267,17 @@ module Gitlab
def
find_or_create_object!
# 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
[
:project
]
=
@project
hash
[
:title
]
=
parsed_relation_hash
[
'title'
]
if
parsed_relation_hash
[
'title'
]
hash
.
delete
(
'project_id'
)
end
if
label?
label
=
GroupProjectFinder
.
find_or_new
(
Label
,
finder_hash
)
parsed_relation_hash
.
delete
(
'priorities'
)
if
label
.
persisted?
parsed_relation_hash
.
delete
(
'type'
)
label
.
save!
label
GroupProjectFinder
.
find_or_new
(
Label
,
finder_hash
)
else
object
=
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
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
end
end
...
...
spec/lib/gitlab/import_export/group_project_finder_spec.rb
View file @
8522173e
...
...
@@ -16,15 +16,15 @@ describe Gitlab::ImportExport::GroupProjectFinder do
expect
(
described_class
.
find_or_new
(
Label
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)).
to
eq
(
group_label
)
project:
project
,
group:
project
.
group
)).
to
eq
(
group_label
)
end
it
'initializes a new label'
do
label
=
described_class
.
find_or_new
(
Label
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)
project:
project
,
group:
project
.
group
)
expect
(
label
.
persisted?
).
to
be
false
end
...
...
@@ -32,8 +32,8 @@ describe Gitlab::ImportExport::GroupProjectFinder do
it
'creates a new label'
do
label
=
described_class
.
find_or_create
(
Label
,
title:
'group label'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)
project:
project
,
group:
project
.
group
)
expect
(
label
.
persisted?
).
to
be
true
end
...
...
@@ -45,15 +45,15 @@ describe Gitlab::ImportExport::GroupProjectFinder do
expect
(
described_class
.
find_or_new
(
Milestone
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)).
to
eq
(
milestone
)
project:
project
,
group:
project
.
group
)).
to
eq
(
milestone
)
end
it
'initializes a new milestone'
do
milestone
=
described_class
.
find_or_new
(
Milestone
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)
project:
project
,
group:
project
.
group
)
expect
(
milestone
.
persisted?
).
to
be
false
end
...
...
@@ -61,8 +61,8 @@ describe Gitlab::ImportExport::GroupProjectFinder do
it
'creates a new milestone'
do
milestone
=
described_class
.
find_or_create
(
Milestone
,
title:
'group milestone'
,
'project_id'
=>
project
.
id
,
'group_id'
=>
project
.
group
.
id
)
project:
project
,
group:
project
.
group
)
expect
(
milestone
.
persisted?
).
to
be
true
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