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
Boxiang Sun
gitlab-ce
Commits
de025ad2
Commit
de025ad2
authored
Oct 06, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing group label import
parent
a0b8275d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
19 deletions
+29
-19
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+27
-17
spec/lib/gitlab/import_export/project.light.json
spec/lib/gitlab/import_export/project.light.json
+2
-2
No files found.
lib/gitlab/import_export/relation_factory.rb
View file @
de025ad2
...
@@ -56,22 +56,21 @@ module Gitlab
...
@@ -56,22 +56,21 @@ module Gitlab
private
private
def
setup_models
def
setup_models
if
@relation_name
==
:notes
case
@relation_name
set_note_author
when
:merge_request_diff
then
setup_st_diff_commits
when
:merge_request_diff_files
then
setup_diff
# attachment is deprecated and note uploads are handled by Markdown uploader
when
:notes
then
setup_note
@relation_hash
[
'attachment'
]
=
nil
when
:project_label
,
:project_labels
then
setup_label
when
:milestone
,
:milestones
then
setup_milestone
else
@relation_hash
[
'project_id'
]
=
@project
.
id
end
end
update_user_references
update_user_references
update_project_references
update_project_references
handle_group_label
if
group_label?
reset_tokens!
reset_tokens!
remove_encrypted_attributes!
remove_encrypted_attributes!
set_st_diff_commits
if
@relation_name
==
:merge_request_diff
set_diff
if
@relation_name
==
:merge_request_diff_files
end
end
def
update_user_references
def
update_user_references
...
@@ -82,6 +81,12 @@ module Gitlab
...
@@ -82,6 +81,12 @@ module Gitlab
end
end
end
end
def
setup_note
set_note_author
# attachment is deprecated and note uploads are handled by Markdown uploader
@relation_hash
[
'attachment'
]
=
nil
end
# Sets the author for a note. If the user importing the project
# Sets the author for a note. If the user importing the project
# has admin access, an actual mapping with new project members
# has admin access, an actual mapping with new project members
# will be used. Otherwise, a note stating the original author name
# will be used. Otherwise, a note stating the original author name
...
@@ -134,11 +139,9 @@ module Gitlab
...
@@ -134,11 +139,9 @@ module Gitlab
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
@relation_hash
[
'target_project_id'
]
&&
@relation_hash
[
'target_project_id'
]
==
@relation_hash
[
'source_project_id'
]
end
end
def
group_label?
def
setup_label
@relation_hash
[
'type'
]
==
'GroupLabel'
return
unless
@relation_hash
[
'type'
]
==
'GroupLabel'
end
def
handle_group_label
# If there's no group, move the label to a project label
# If there's no group, move the label to a project label
if
@relation_hash
[
'group_id'
]
if
@relation_hash
[
'group_id'
]
@relation_hash
[
'project_id'
]
=
nil
@relation_hash
[
'project_id'
]
=
nil
...
@@ -148,6 +151,14 @@ module Gitlab
...
@@ -148,6 +151,14 @@ module Gitlab
end
end
end
end
def
setup_milestone
if
@relation_hash
[
'group_id'
]
@relation_hash
[
'group_id'
]
=
@project
.
group
.
id
else
@relation_hash
[
'project_id'
]
=
@project
.
id
end
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
)
...
@@ -196,14 +207,14 @@ module Gitlab
...
@@ -196,14 +207,14 @@ module Gitlab
relation_class:
relation_class
)
relation_class:
relation_class
)
end
end
def
set_st_diff_commits
def
set
up
_st_diff_commits
@relation_hash
[
'st_diffs'
]
=
@relation_hash
.
delete
(
'utf8_st_diffs'
)
@relation_hash
[
'st_diffs'
]
=
@relation_hash
.
delete
(
'utf8_st_diffs'
)
HashUtil
.
deep_symbolize_array!
(
@relation_hash
[
'st_diffs'
])
HashUtil
.
deep_symbolize_array!
(
@relation_hash
[
'st_diffs'
])
HashUtil
.
deep_symbolize_array_with_date!
(
@relation_hash
[
'st_commits'
])
HashUtil
.
deep_symbolize_array_with_date!
(
@relation_hash
[
'st_commits'
])
end
end
def
set_diff
def
set
up
_diff
@relation_hash
[
'diff'
]
=
@relation_hash
.
delete
(
'utf8_diff'
)
@relation_hash
[
'diff'
]
=
@relation_hash
.
delete
(
'utf8_diff'
)
end
end
...
@@ -248,8 +259,7 @@ module Gitlab
...
@@ -248,8 +259,7 @@ module Gitlab
end
end
def
find_or_create_object!
def
find_or_create_object!
# TODO: Trying to find how I can correctly use the correct id depending on the object's type
finder_attributes
=
if
@relation_name
==
:group_label
finder_attributes
=
if
@relation_type
==
:group_label
%w[title group_id]
%w[title group_id]
elsif
parsed_relation_hash
[
'project_id'
]
elsif
parsed_relation_hash
[
'project_id'
]
%w[title project_id]
%w[title project_id]
...
...
spec/lib/gitlab/import_export/project.light.json
View file @
de025ad2
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
"labels"
:
[
"labels"
:
[
{
{
"id"
:
2
,
"id"
:
2
,
"title"
:
"
test2
"
,
"title"
:
"
A project label
"
,
"color"
:
"#428bca"
,
"color"
:
"#428bca"
,
"project_id"
:
8
,
"project_id"
:
8
,
"created_at"
:
"2016-07-22T08:55:44.161Z"
,
"created_at"
:
"2016-07-22T08:55:44.161Z"
,
...
@@ -85,7 +85,7 @@
...
@@ -85,7 +85,7 @@
"updated_at"
:
"2017-08-15T18:37:40.795Z"
,
"updated_at"
:
"2017-08-15T18:37:40.795Z"
,
"label"
:
{
"label"
:
{
"id"
:
6
,
"id"
:
6
,
"title"
:
"project label"
,
"title"
:
"
Another
project label"
,
"color"
:
"#A8D695"
,
"color"
:
"#A8D695"
,
"project_id"
:
null
,
"project_id"
:
null
,
"created_at"
:
"2017-08-15T18:37:19.698Z"
,
"created_at"
:
"2017-08-15T18:37:19.698Z"
,
...
...
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