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
Tatuya Kamada
gitlab-ce
Commits
54527477
Commit
54527477
authored
Dec 21, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error importing label priorities and added relevant spec
parent
528c3e2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+23
-5
spec/lib/gitlab/import_export/project.json
spec/lib/gitlab/import_export/project.json
+22
-0
No files found.
lib/gitlab/import_export/relation_factory.rb
View file @
54527477
...
@@ -22,7 +22,7 @@ module Gitlab
...
@@ -22,7 +22,7 @@ module Gitlab
IMPORTED_OBJECT_MAX_RETRIES
=
5
.
freeze
IMPORTED_OBJECT_MAX_RETRIES
=
5
.
freeze
EXISTING_OBJECT_CHECK
=
%i[milestone milestones label labels project_label project_labels
project_label group_label
]
.
freeze
EXISTING_OBJECT_CHECK
=
%i[milestone milestones label labels project_label project_labels
group_label group_labels
]
.
freeze
def
self
.
create
(
*
args
)
def
self
.
create
(
*
args
)
new
(
*
args
).
create
new
(
*
args
).
create
...
@@ -189,7 +189,7 @@ module Gitlab
...
@@ -189,7 +189,7 @@ module Gitlab
# Otherwise always create the record, skipping the extra SELECT clause.
# Otherwise always create the record, skipping the extra SELECT clause.
@existing_or_new_object
||=
begin
@existing_or_new_object
||=
begin
if
EXISTING_OBJECT_CHECK
.
include?
(
@relation_name
)
if
EXISTING_OBJECT_CHECK
.
include?
(
@relation_name
)
attribute_hash
=
attribute_hash_for
([
'events'
,
'priorities'
])
attribute_hash
=
attribute_hash_for
([
'events'
])
existing_object
.
assign_attributes
(
attribute_hash
)
if
attribute_hash
.
any?
existing_object
.
assign_attributes
(
attribute_hash
)
if
attribute_hash
.
any?
...
@@ -210,9 +210,8 @@ module Gitlab
...
@@ -210,9 +210,8 @@ module Gitlab
def
existing_object
def
existing_object
@existing_object
||=
@existing_object
||=
begin
begin
finder_attributes
=
@relation_name
==
:group_label
?
%w[title group_id]
:
%w[title project_id]
existing_object
=
find_or_create_object!
finder_hash
=
parsed_relation_hash
.
slice
(
*
finder_attributes
)
existing_object
=
relation_class
.
find_or_create_by
(
finder_hash
)
# Done in two steps, as MySQL behaves differently than PostgreSQL using
# 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.
# the +find_or_create_by+ method and does not return the ID the second time.
existing_object
.
update!
(
parsed_relation_hash
)
existing_object
.
update!
(
parsed_relation_hash
)
...
@@ -224,6 +223,25 @@ module Gitlab
...
@@ -224,6 +223,25 @@ module Gitlab
@relation_name
==
:services
&&
parsed_relation_hash
[
'type'
]
&&
@relation_name
==
:services
&&
parsed_relation_hash
[
'type'
]
&&
!
Object
.
const_defined?
(
parsed_relation_hash
[
'type'
])
!
Object
.
const_defined?
(
parsed_relation_hash
[
'type'
])
end
end
def
find_or_create_object!
finder_attributes
=
@relation_name
==
:group_label
?
%w[title group_id]
:
%w[title project_id]
finder_hash
=
parsed_relation_hash
.
slice
(
*
finder_attributes
)
if
label?
label
=
relation_class
.
find_or_initialize_by
(
finder_hash
)
parsed_relation_hash
.
delete
(
'priorities'
)
if
label
.
persisted?
label
.
save!
label
else
relation_class
.
find_or_create_by
(
finder_hash
)
end
end
def
label?
@relation_name
.
to_s
.
include?
(
'label'
)
end
end
end
end
end
end
end
spec/lib/gitlab/import_export/project.json
View file @
54527477
...
@@ -15,6 +15,28 @@
...
@@ -15,6 +15,28 @@
"type"
:
"ProjectLabel"
,
"type"
:
"ProjectLabel"
,
"priorities"
:
[
"priorities"
:
[
]
]
},
{
"id"
:
3
,
"title"
:
"test3"
,
"color"
:
"#428bca"
,
"group_id"
:
8
,
"created_at"
:
"2016-07-22T08:55:44.161Z"
,
"updated_at"
:
"2016-07-22T08:55:44.161Z"
,
"template"
:
false
,
"description"
:
""
,
"project_id"
:
null
,
"type"
:
"GroupLabel"
,
"priorities"
:
[
{
"id"
:
1
,
"project_id"
:
5
,
"label_id"
:
1
,
"priority"
:
1
,
"created_at"
:
"2016-10-18T09:35:43.338Z"
,
"updated_at"
:
"2016-10-18T09:35:43.338Z"
}
]
}
}
],
],
"issues"
:
[
"issues"
:
[
...
...
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