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
3a14ae3a
Commit
3a14ae3a
authored
Jun 25, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor code based on feedback
parent
ec394d49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
20 deletions
+22
-20
lib/gitlab/import_export/group_project_object_builder.rb
lib/gitlab/import_export/group_project_object_builder.rb
+12
-8
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+2
-2
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+8
-10
No files found.
lib/gitlab/import_export/group_project_object_builder.rb
View file @
3a14ae3a
...
@@ -36,19 +36,17 @@ module Gitlab
...
@@ -36,19 +36,17 @@ module Gitlab
end
end
def
where_clause
def
where_clause
return
{
project_id:
@project
.
id
}
unless
milestone?
||
label?
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
if
@group
if
@group
project_
clause
(
key
,
value
).
or
(
group_clause
(
key
,
value
)
)
project_
group_clause
(
key
,
value
)
else
else
project_clause
(
key
,
value
)
project_clause
(
key
,
value
)
end
end
end
.
reduce
(
:or
)
end
.
reduce
(
:or
)
end
end
def
group_clause
(
key
,
value
)
def
project_
group_clause
(
key
,
value
)
table
[
key
].
eq
(
value
).
and
(
table
[
:
group_id
].
eq
(
@group
.
id
))
table
[
key
].
eq
(
value
).
and
(
table
[
:
project_id
].
eq
(
@project
.
id
).
or
(
table
[
:group_id
].
eq
(
@group
.
id
)
))
end
end
def
project_clause
(
key
,
value
)
def
project_clause
(
key
,
value
)
...
@@ -92,11 +90,17 @@ module Gitlab
...
@@ -92,11 +90,17 @@ module Gitlab
# 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'
])
group_milestone
=
@project
.
milestones
.
find_by
(
iid:
@attributes
[
'iid'
])
group_milestone
.
update!
(
iid:
max_milestone_iid
+
1
)
if
group_milestone
group_milestone
.
update!
(
iid:
max_milestone_iid
(
group_milestone
)
)
if
group_milestone
end
end
def
max_milestone_iid
def
max_milestone_iid
(
group_milestone
)
[
@attributes
[
'iid'
],
@project
.
milestones
.
maximum
(
:iid
)].
compact
.
max
init_iid
=
[
@attributes
[
'iid'
],
@project
.
milestones
.
maximum
(
:iid
)].
compact
.
max
+
1
InternalId
::
InternalIdGenerator
.
new
(
group_milestone
,
{
project:
@project
},
:milestones
,
init_iid
).
generate
end
end
end
end
end
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
3a14ae3a
module
Gitlab
module
Gitlab
module
ImportExport
module
ImportExport
class
ProjectTreeRestorer
class
ProjectTreeRestorer
# Relations which cannot be saved at project level
# Relations which cannot be saved at project level
(and have a group assigned)
GROUP_MODELS
=
[
GroupLabel
,
Milestone
].
freeze
GROUP_MODELS
=
[
GroupLabel
,
Milestone
].
freeze
def
initialize
(
user
:,
shared
:,
project
:)
def
initialize
(
user
:,
shared
:,
project
:)
...
@@ -83,7 +83,7 @@ module Gitlab
...
@@ -83,7 +83,7 @@ module Gitlab
# For example, in the case of an existing group label that matched the title.
# For example, in the case of an existing group label that matched the title.
def
remove_group_models
(
relation_hash
)
def
remove_group_models
(
relation_hash
)
relation_hash
.
reject!
do
|
value
|
relation_hash
.
reject!
do
|
value
|
value
.
respond_to?
(
:group_id
)
&&
value
.
group_id
&&
GROUP_MODELS
.
include?
(
value
.
class
)
GROUP_MODELS
.
include?
(
value
.
class
)
&&
value
.
group_id
end
end
end
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
3a14ae3a
...
@@ -150,16 +150,16 @@ module Gitlab
...
@@ -150,16 +150,16 @@ module Gitlab
end
end
def
update_project_references
def
update_project_references
project_id
=
@relation_hash
.
delete
(
'project_id'
)
# If source and target are the same, populate them with the new project ID.
# If source and target are the same, populate them with the new project ID.
if
@relation_hash
[
'source_project_id'
]
if
@relation_hash
[
'source_project_id'
]
@relation_hash
[
'source_project_id'
]
=
same_source_and_target?
?
project_id
:
MergeRequestParser
::
FORKED_PROJECT_ID
@relation_hash
[
'source_project_id'
]
=
same_source_and_target?
?
@relation_hash
[
'project_id'
]
:
MergeRequestParser
::
FORKED_PROJECT_ID
end
end
# project_id may not be part of the export, but we always need to populate it if required.
@relation_hash
[
'target_project_id'
]
=
@relation_hash
[
'project_id'
]
if
@relation_hash
[
'target_project_id'
]
@relation_hash
[
'project_id'
]
=
project_id
end
@relation_hash
[
'target_project_id'
]
=
project_id
if
@relation_hash
[
'target_project_id'
]
def
same_source_and_target?
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
end
def
update_group_references
def
update_group_references
...
@@ -169,10 +169,6 @@ module Gitlab
...
@@ -169,10 +169,6 @@ module Gitlab
@relation_hash
[
'group_id'
]
=
@project
.
group
&
.
id
@relation_hash
[
'group_id'
]
=
@project
.
group
&
.
id
end
end
def
same_source_and_target?
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
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
)
...
@@ -267,6 +263,8 @@ module Gitlab
...
@@ -267,6 +263,8 @@ module Gitlab
end
end
def
find_or_create_object!
def
find_or_create_object!
return
relation_class
.
find_or_create_by
(
project_id:
@project
.
id
)
if
@relation_name
==
:project_feature
# 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'
)
...
...
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