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
Show 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
...
@@ -12,7 +12,7 @@ module Issuable
def
execute
def
execute
update_attributes
=
{
labels:
cloneable_labels
}
update_attributes
=
{
labels:
cloneable_labels
}
milestone
=
cloneable_milestone
milestone
=
matching_milestone
(
original_entity
.
milestone
&
.
title
)
update_attributes
[
:milestone
]
=
milestone
if
milestone
.
present?
update_attributes
[
:milestone
]
=
milestone
if
milestone
.
present?
new_entity
.
update
(
update_attributes
)
new_entity
.
update
(
update_attributes
)
...
@@ -23,11 +23,8 @@ module Issuable
...
@@ -23,11 +23,8 @@ module Issuable
private
private
def
cloneable_milestone
def
matching_milestone
(
title
)
return
unless
new_entity
.
supports_milestone?
return
if
title
.
blank?
||
!
new_entity
.
supports_milestone?
title
=
original_entity
.
milestone
&
.
title
return
unless
title
params
=
{
title:
title
,
project_ids:
new_entity
.
project
&
.
id
,
group_ids:
group
&
.
id
}
params
=
{
title:
title
,
project_ids:
new_entity
.
project
&
.
id
,
group_ids:
group
&
.
id
}
...
@@ -49,29 +46,32 @@ module Issuable
...
@@ -49,29 +46,32 @@ module Issuable
end
end
def
copy_resource_label_events
def
copy_resource_label_events
original_entity
.
resource_label_events
.
find_in_batches
do
|
batch
|
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
events
=
batch
.
map
do
|
event
|
entity_key
=
new_entity
.
is_a?
(
Issue
)
?
'issue_id'
:
'epic_id'
copy_events
(
ResourceLabelEvent
.
table_name
,
original_entity
.
resource_label_events
)
do
|
event
|
event
.
attributes
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
'action'
=>
ResourceLabelEvent
.
actions
[
event
.
action
])
.
merge
(
entity_key
=>
new_entity
.
id
,
'action'
=>
ResourceLabelEvent
.
actions
[
event
.
action
])
end
end
Gitlab
::
Database
.
bulk_insert
(
ResourceLabelEvent
.
table_name
,
events
)
end
end
end
def
copy_resource_weight_events
def
copy_resource_weight_events
return
unless
original_entity
.
respond_to?
(
: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
|
events
=
batch
.
map
do
|
event
|
event
.
attributes
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
except
(
'id'
,
'reference'
,
'reference_html'
)
.
merge
(
'issue_id'
=>
new_entity
.
id
)
.
merge
(
'issue_id'
=>
new_entity
.
id
)
end
end
end
def
copy_events
(
table_name
,
events_to_copy
)
events_to_copy
.
find_in_batches
do
|
batch
|
events
=
batch
.
map
do
|
event
|
yield
(
event
)
end
.
compact
Gitlab
::
Database
.
bulk_insert
(
ResourceWeightEvent
.
table_name
,
events
)
Gitlab
::
Database
.
bulk_insert
(
table_name
,
events
)
end
end
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