2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issuable
|
|
|
|
module Clone
|
|
|
|
class BaseService < IssuableBaseService
|
2022-08-13 15:12:31 +05:30
|
|
|
attr_reader :original_entity, :new_entity
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
alias_method :old_project, :project
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def execute(original_entity, target_parent)
|
2019-02-15 15:39:39 +05:30
|
|
|
@original_entity = original_entity
|
2022-08-13 15:12:31 +05:30
|
|
|
@target_parent = target_parent
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
# Using transaction because of a high resources footprint
|
|
|
|
# on rewriting notes (unfolding references)
|
|
|
|
#
|
2021-10-27 15:23:28 +05:30
|
|
|
ApplicationRecord.transaction do
|
2019-02-15 15:39:39 +05:30
|
|
|
@new_entity = create_new_entity
|
2022-08-27 11:52:29 +05:30
|
|
|
@new_entity.system_note_timestamp = nil
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
update_new_entity
|
|
|
|
update_old_entity
|
|
|
|
create_notes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
attr_reader :target_parent
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def rewritten_old_entity_attributes(include_milestone: true)
|
|
|
|
Gitlab::Issuable::Clone::AttributesRewriter.new(
|
|
|
|
current_user,
|
|
|
|
original_entity,
|
|
|
|
target_parent
|
|
|
|
).execute(include_milestone: include_milestone)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def update_new_entity
|
2020-10-24 23:57:45 +05:30
|
|
|
update_new_entity_description
|
|
|
|
copy_award_emoji
|
|
|
|
copy_notes
|
2022-08-13 15:12:31 +05:30
|
|
|
copy_resource_events
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def update_new_entity_description
|
2022-07-23 23:45:48 +05:30
|
|
|
update_description_params = MarkdownContentRewriterService.new(
|
2020-10-24 23:57:45 +05:30
|
|
|
current_user,
|
2022-07-23 23:45:48 +05:30
|
|
|
original_entity,
|
|
|
|
:description,
|
2020-10-24 23:57:45 +05:30
|
|
|
original_entity.project,
|
|
|
|
new_parent
|
|
|
|
).execute
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
new_entity.update!(update_description_params)
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def copy_award_emoji
|
|
|
|
AwardEmojis::CopyService.new(original_entity, new_entity).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_notes
|
|
|
|
Notes::CopyService.new(current_user, original_entity, new_entity).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_resource_events
|
|
|
|
Gitlab::Issuable::Clone::CopyResourceEventsService.new(current_user, original_entity, new_entity).execute
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update_old_entity
|
|
|
|
close_issue
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_notes
|
|
|
|
add_note_from
|
|
|
|
add_note_to
|
|
|
|
end
|
|
|
|
|
|
|
|
def close_issue
|
2023-04-23 21:23:45 +05:30
|
|
|
close_service = Issues::CloseService.new(container: old_project, current_user: current_user)
|
2021-09-30 23:02:18 +05:30
|
|
|
close_service.execute(original_entity, notifications: false, system_note: true)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new_parent
|
2020-10-24 23:57:45 +05:30
|
|
|
new_entity.resource_parent
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def relative_position
|
2022-08-13 15:12:31 +05:30
|
|
|
return if original_entity.project.root_ancestor.id != target_parent.root_ancestor.id
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
original_entity.relative_position
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Issuable::Clone::BaseService.prepend_mod_with('Issuable::Clone::BaseService')
|