diff options
Diffstat (limited to 'app/services/issuable/clone/attributes_rewriter.rb')
-rw-r--r-- | app/services/issuable/clone/attributes_rewriter.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/services/issuable/clone/attributes_rewriter.rb b/app/services/issuable/clone/attributes_rewriter.rb index 2b436f6322c..135ab011d69 100644 --- a/app/services/issuable/clone/attributes_rewriter.rb +++ b/app/services/issuable/clone/attributes_rewriter.rb @@ -19,6 +19,7 @@ module Issuable copy_resource_label_events copy_resource_weight_events + copy_resource_milestone_events end private @@ -65,6 +66,23 @@ module Issuable end end + def copy_resource_milestone_events + entity_key = new_entity.class.name.underscore.foreign_key + + copy_events(ResourceMilestoneEvent.table_name, original_entity.resource_milestone_events) do |event| + matching_destination_milestone = matching_milestone(event.milestone.title) + + if matching_destination_milestone.present? + event.attributes + .except('id', 'reference', 'reference_html') + .merge(entity_key => new_entity.id, + 'milestone_id' => matching_destination_milestone.id, + 'action' => ResourceMilestoneEvent.actions[event.action], + 'state' => ResourceMilestoneEvent.states[event.state]) + end + end + end + def copy_events(table_name, events_to_copy) events_to_copy.find_in_batches do |batch| events = batch.map do |event| |