summaryrefslogtreecommitdiff
path: root/app/services/issuable
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-27 15:10:16 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-27 15:10:16 +0000
commitc2908ec6a0d7b62996cdb8da0350705bdad691bf (patch)
tree1280356af695cfb7774b2aa9ea08631292795bb9 /app/services/issuable
parent45999bfdec535b959f46fa4ed8f761bb3eadfed4 (diff)
downloadgitlab-ce-c2908ec6a0d7b62996cdb8da0350705bdad691bf.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/issuable')
-rw-r--r--app/services/issuable/clone/attributes_rewriter.rb33
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