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
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
end
def
where_clause
return
{
project_id:
@project
.
id
}
unless
milestone?
||
label?
@attributes
.
slice
(
'title'
).
map
do
|
key
,
value
|
if
@group
project_
clause
(
key
,
value
).
or
(
group_clause
(
key
,
value
)
)
project_
group_clause
(
key
,
value
)
else
project_clause
(
key
,
value
)
end
end
.
reduce
(
:or
)
end
def
group_clause
(
key
,
value
)
table
[
key
].
eq
(
value
).
and
(
table
[
:
group_id
].
eq
(
@group
.
id
))
def
project_
group_clause
(
key
,
value
)
table
[
key
].
eq
(
value
).
and
(
table
[
:
project_id
].
eq
(
@project
.
id
).
or
(
table
[
:group_id
].
eq
(
@group
.
id
)
))
end
def
project_clause
(
key
,
value
)
...
...
@@ -92,11 +90,17 @@ module Gitlab
# we set the IID as the maximum. The rest of them are fixed.
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
def
max_milestone_iid
[
@attributes
[
'iid'
],
@project
.
milestones
.
maximum
(
:iid
)].
compact
.
max
def
max_milestone_iid
(
group_milestone
)
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
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
3a14ae3a
module
Gitlab
module
ImportExport
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
def
initialize
(
user
:,
shared
:,
project
:)
...
...
@@ -83,7 +83,7 @@ module Gitlab
# For example, in the case of an existing group label that matched the title.
def
remove_group_models
(
relation_hash
)
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
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
3a14ae3a
...
...
@@ -150,16 +150,16 @@ module Gitlab
end
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
@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
# project_id may not be part of the export, but we always need to populate it if required.
@relation_hash
[
'project_id'
]
=
project_id
@relation_hash
[
'target_project_id'
]
=
project_id
if
@relation_hash
[
'target_project_id'
]
@relation_hash
[
'target_project_id'
]
=
@relation_hash
[
'project_id'
]
if
@relation_hash
[
'target_project_id'
]
end
def
same_source_and_target?
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
def
update_group_references
...
...
@@ -169,10 +169,6 @@ module Gitlab
@relation_hash
[
'group_id'
]
=
@project
.
group
&
.
id
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!
return
unless
Gitlab
::
ImportExport
.
reset_tokens?
&&
TOKEN_RESET_MODELS
.
include?
(
@relation_name
.
to_s
)
...
...
@@ -267,6 +263,8 @@ module Gitlab
end
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
finder_hash
=
parsed_relation_hash
.
tap
do
|
hash
|
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