2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
module Issues
|
|
|
|
class DuplicateService < Issues::BaseService
|
|
|
|
def execute(duplicate_issue, canonical_issue)
|
|
|
|
return if canonical_issue == duplicate_issue
|
|
|
|
return unless can?(current_user, :update_issue, duplicate_issue)
|
|
|
|
return unless can?(current_user, :create_note, canonical_issue)
|
|
|
|
|
|
|
|
create_issue_duplicate_note(duplicate_issue, canonical_issue)
|
|
|
|
create_issue_canonical_note(canonical_issue, duplicate_issue)
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
close_service.new(container: project, current_user: current_user).execute(duplicate_issue)
|
2019-12-04 20:38:33 +05:30
|
|
|
duplicate_issue.update(duplicated_to: canonical_issue)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
relate_two_issues(duplicate_issue, canonical_issue)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_issue_duplicate_note(duplicate_issue, canonical_issue)
|
|
|
|
SystemNoteService.mark_duplicate_issue(duplicate_issue, duplicate_issue.project, current_user, canonical_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_issue_canonical_note(canonical_issue, duplicate_issue)
|
|
|
|
SystemNoteService.mark_canonical_issue_of_duplicate(canonical_issue, canonical_issue.project, current_user, duplicate_issue)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
def relate_two_issues(duplicate_issue, canonical_issue)
|
|
|
|
params = { target_issuable: canonical_issue }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
IssueLinks::CreateService.new(duplicate_issue, current_user, params).execute
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|