diff options
Diffstat (limited to 'app/services/issuable/clone/attributes_rewriter.rb')
-rw-r--r-- | app/services/issuable/clone/attributes_rewriter.rb | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/app/services/issuable/clone/attributes_rewriter.rb b/app/services/issuable/clone/attributes_rewriter.rb index 55f5629baac..78d3fb2e4d2 100644 --- a/app/services/issuable/clone/attributes_rewriter.rb +++ b/app/services/issuable/clone/attributes_rewriter.rb @@ -67,22 +67,30 @@ module Issuable end def copy_resource_milestone_events - entity_key = new_entity.class.name.underscore.foreign_key + return unless milestone_events_supported? 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') - .merge(entity_key => new_entity.id, - 'milestone_id' => matching_destination_milestone.id, - 'action' => ResourceMilestoneEvent.actions[event.action], - 'state' => ResourceMilestoneEvent.states[event.state]) + if event.remove? + event_attributes_with_milestone(event, nil) + else + matching_destination_milestone = matching_milestone(event.milestone_title) + + event_attributes_with_milestone(event, matching_destination_milestone) if matching_destination_milestone.present? end end end + def event_attributes_with_milestone(event, milestone) + entity_key = new_entity.class.name.underscore.foreign_key + + event.attributes + .except('id') + .merge(entity_key => new_entity.id, + 'milestone_id' => milestone&.id, + 'action' => ResourceMilestoneEvent.actions[event.action], + 'state' => ResourceMilestoneEvent.states[event.state]) + end + def copy_events(table_name, events_to_copy) events_to_copy.find_in_batches do |batch| events = batch.map do |event| @@ -96,6 +104,11 @@ module Issuable def entity_key new_entity.class.name.parameterize('_').foreign_key end + + def milestone_events_supported? + original_entity.respond_to?(:resource_milestone_events) && + new_entity.respond_to?(:resource_milestone_events) + end end end end |