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
765ec848
Commit
765ec848
authored
Jan 30, 2020
by
Patrick Derichs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generalize copying of events within AttributesRewriter
parent
7f2ea03a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
app/services/issuable/clone/attributes_rewriter.rb
app/services/issuable/clone/attributes_rewriter.rb
+20
-20
No files found.
app/services/issuable/clone/attributes_rewriter.rb
View file @
765ec848
...
...
@@ -12,7 +12,7 @@ module Issuable
def
execute
update_attributes
=
{
labels:
cloneable_labels
}
milestone
=
cloneable_milestone
milestone
=
matching_milestone
(
original_entity
.
milestone
&
.
title
)
update_attributes
[
:milestone
]
=
milestone
if
milestone
.
present?
new_entity
.
update
(
update_attributes
)
...
...
@@ -23,11 +23,8 @@ module Issuable
private
def
cloneable_milestone
return
unless
new_entity
.
supports_milestone?
title
=
original_entity
.
milestone
&
.
title
return
unless
title
def
matching_milestone
(
title
)
return
if
title
.
blank?
||
!
new_entity
.
supports_milestone?
params
=
{
title:
title
,
project_ids:
new_entity
.
project
&
.
id
,
group_ids:
group
&
.
id
}
...
...
@@ -49,29 +46,32 @@ module Issuable
end
def
copy_resource_label_events
original_entity
.
resource_label_events
.
find_in_batches
do
|
batch
|
events
=
batch
.
map
do
|
event
|
entity_key
=
new_entity
.
is_a?
(
Issue
)
?
'issue_id'
:
'epic_id'
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
'action'
=>
ResourceLabelEvent
.
actions
[
event
.
action
])
end
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
Gitlab
::
Database
.
bulk_insert
(
ResourceLabelEvent
.
table_name
,
events
)
copy_events
(
ResourceLabelEvent
.
table_name
,
original_entity
.
resource_label_events
)
do
|
event
|
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
'action'
=>
ResourceLabelEvent
.
actions
[
event
.
action
])
end
end
def
copy_resource_weight_events
return
unless
original_entity
.
respond_to?
(
:resource_weight_events
)
original_entity
.
resource_weight_events
.
find_in_batches
do
|
batch
|
copy_events
(
ResourceWeightEvent
.
table_name
,
original_entity
.
resource_weight_events
)
do
|
event
|
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
'issue_id'
=>
new_entity
.
id
)
end
end
def
copy_events
(
table_name
,
events_to_copy
)
events_to_copy
.
find_in_batches
do
|
batch
|
events
=
batch
.
map
do
|
event
|
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
'issue_id'
=>
new_entity
.
id
)
end
yield
(
event
)
end
.
compact
Gitlab
::
Database
.
bulk_insert
(
ResourceWeightEvent
.
table_name
,
events
)
Gitlab
::
Database
.
bulk_insert
(
table_name
,
events
)
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