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
4eebd231
Commit
4eebd231
authored
Jun 27, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code based on feedback
parent
79208294
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
50 deletions
+33
-50
lib/gitlab/import_export/group_project_object_builder.rb
lib/gitlab/import_export/group_project_object_builder.rb
+17
-34
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+2
-2
spec/lib/gitlab/import_export/group_project_object_builder_spec.rb
...gitlab/import_export/group_project_object_builder_spec.rb
+14
-14
No files found.
lib/gitlab/import_export/group_project_object_builder.rb
View file @
4eebd231
...
@@ -19,38 +19,27 @@ module Gitlab
...
@@ -19,38 +19,27 @@ module Gitlab
def
initialize
(
klass
,
attributes
)
def
initialize
(
klass
,
attributes
)
@klass
=
klass
<
Label
?
Label
:
klass
@klass
=
klass
<
Label
?
Label
:
klass
@attributes
=
attributes
@attributes
=
attributes
@group
=
@attributes
[
:group
]
@group
=
@attributes
[
'group'
]
@project
=
@attributes
[
:project
]
@project
=
@attributes
[
'project'
]
end
end
def
find
def
find
find_or_action
do
find_object
||
@klass
.
create
(
project_attributes
)
label?
?
@klass
.
new
(
project_attributes
)
:
@klass
.
create
(
project_attributes
)
end
end
end
private
private
def
find_o
r_action
(
&
block
)
def
find_o
bject
@klass
.
where
(
where_clause
).
first
||
yield
@klass
.
where
(
where_clause
).
first
end
end
def
where_clause
def
where_clause
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
if
@group
scope_clause
=
table
[
:project_id
].
eq
(
@project
.
id
)
project_group_clause
(
key
,
value
)
scope_clause
=
scope_clause
.
or
(
table
[
:group_id
].
eq
(
@group
.
id
))
if
@group
else
project_clause
(
key
,
value
)
end
end
.
reduce
(
:or
)
end
def
project_group_clause
(
key
,
value
)
table
[
key
].
eq
(
value
).
and
(
scope_clause
)
table
[
key
].
eq
(
value
).
and
(
table
[
:project_id
].
eq
(
@project
.
id
).
or
(
table
[
:group_id
].
eq
(
@group
.
id
)))
end
.
reduce
(
:or
)
end
def
project_clause
(
key
,
value
)
table
[
key
].
eq
(
value
).
and
(
table
[
:project_id
].
eq
(
@project
.
id
))
end
end
def
table
def
table
...
@@ -58,7 +47,7 @@ module Gitlab
...
@@ -58,7 +47,7 @@ module Gitlab
end
end
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'
# Always create project labels
atts
[
'type'
]
=
'ProjectLabel'
# Always create project labels
elsif
milestone?
elsif
milestone?
...
@@ -80,27 +69,21 @@ module Gitlab
...
@@ -80,27 +69,21 @@ module Gitlab
@klass
==
Milestone
@klass
==
Milestone
end
end
# If an existing group milesone used the IID
# If an existing group miles
t
one used the IID
# claim the IID back and set the group milestone to use one available
# claim the IID back and set the group milestone to use one available
# This is nec
c
essary to fix situations like the following:
# This is necessary to fix situations like the following:
# - Importing into a user namespace project with exported group milestones
# - Importing into a user namespace project with exported group milestones
# where the IID of the Group milestone could conflict with a project one.
# where the IID of the Group milestone could conflict with a project one.
def
claim_iid
def
claim_iid
# The milestone has to be a group milestone, as it's the only case where
# The milestone has to be a group milestone, as it's the only case where
# we set the IID as the maximum. The rest of them are fixed.
# we set the IID as the maximum. The rest of them are fixed.
group_milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
group_milestone
.
update!
(
iid:
max_milestone_iid
(
group_milestone
))
if
group_milestone
end
def
max_milestone_iid
(
group_milestone
)
return
unless
milestone
init_iid
=
[
@attributes
[
'iid'
],
@project
.
milestones
.
maximum
(
:iid
)].
compact
.
max
+
1
InternalId
::
InternalIdGenerator
.
new
(
group_milestone
,
milestone
.
iid
=
nil
{
project:
@project
},
milestone
.
ensure_project_iid!
:milestones
,
milestone
.
save!
init_iid
).
generate
end
end
end
end
end
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
4eebd231
...
@@ -267,8 +267,8 @@ module Gitlab
...
@@ -267,8 +267,8 @@ module Gitlab
# Can't use IDs as validation exists calling `group` or `project` attributes
# Can't use IDs as validation exists calling `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
.
delete
(
'project_id'
)
hash
.
delete
(
'project_id'
)
end
end
...
...
spec/lib/gitlab/import_export/group_project_object_builder_spec.rb
View file @
4eebd231
...
@@ -15,18 +15,18 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
...
@@ -15,18 +15,18 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
group_label
=
create
(
:group_label
,
'name'
:
'group label'
,
'group'
:
project
.
group
)
group_label
=
create
(
:group_label
,
'name'
:
'group label'
,
'group'
:
project
.
group
)
expect
(
described_class
.
build
(
Label
,
expect
(
described_class
.
build
(
Label
,
title:
'group label'
,
'title'
=>
'group label'
,
project:
project
,
'project'
=>
project
,
group:
project
.
group
)).
to
eq
(
group_label
)
'group'
=>
project
.
group
)).
to
eq
(
group_label
)
end
end
it
'
initializ
es a new label'
do
it
'
creat
es a new label'
do
label
=
described_class
.
build
(
Label
,
label
=
described_class
.
build
(
Label
,
title:
'group label'
,
'title'
=>
'group label'
,
project:
project
,
'project'
=>
project
,
group:
project
.
group
)
'group'
=>
project
.
group
)
expect
(
label
.
persisted?
).
to
be
fals
e
expect
(
label
.
persisted?
).
to
be
tru
e
end
end
end
end
...
@@ -35,16 +35,16 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
...
@@ -35,16 +35,16 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
milestone
=
create
(
:milestone
,
'name'
=>
'group milestone'
,
'group'
=>
project
.
group
)
milestone
=
create
(
:milestone
,
'name'
=>
'group milestone'
,
'group'
=>
project
.
group
)
expect
(
described_class
.
build
(
Milestone
,
expect
(
described_class
.
build
(
Milestone
,
title:
'group milestone'
,
'title'
=>
'group milestone'
,
project:
project
,
'project'
=>
project
,
group:
project
.
group
)).
to
eq
(
milestone
)
'group'
=>
project
.
group
)).
to
eq
(
milestone
)
end
end
it
'creates a new milestone'
do
it
'creates a new milestone'
do
milestone
=
described_class
.
build
(
Milestone
,
milestone
=
described_class
.
build
(
Milestone
,
title:
'group milestone'
,
'title'
=>
'group milestone'
,
project:
project
,
'project'
=>
project
,
group:
project
.
group
)
'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