debian-mirror-gitlab/app/services/discussions/resolve_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Discussions
class ResolveService < Discussions::BaseService
2020-06-23 00:09:42 +05:30
include Gitlab::Utils::StrongMemoize
def initialize(project, user = nil, params = {})
@discussions = Array.wrap(params.fetch(:one_or_more_discussions))
@follow_up_issue = params[:follow_up_issue]
@resolved_count = 0
raise ArgumentError, 'Discussions must be all for the same noteable' \
unless noteable_is_same?
super
end
def execute
discussions.each(&method(:resolve_discussion))
process_auto_merge
end
private
attr_accessor :discussions, :follow_up_issue
def noteable_is_same?
return true unless discussions.size > 1
# Perform this check without fetching extra records
discussions.all? do |discussion|
discussion.noteable_type == first_discussion.noteable_type &&
discussion.noteable_id == first_discussion.noteable_id
end
2017-08-17 22:00:37 +05:30
end
def resolve_discussion(discussion)
return unless discussion.can_resolve?(current_user)
discussion.resolve!(current_user)
2020-06-23 00:09:42 +05:30
@resolved_count += 1
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
if merge_request
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
.track_resolve_thread_action(user: current_user)
2021-06-08 01:23:25 +05:30
MergeRequests::ResolvedDiscussionNotificationService.new(project: project, current_user: current_user).execute(merge_request)
2021-03-11 19:13:27 +05:30
end
2021-09-04 01:27:46 +05:30
resolve_user_todos_for(discussion)
2017-08-17 22:00:37 +05:30
SystemNoteService.discussion_continued_in_issue(discussion, project, current_user, follow_up_issue) if follow_up_issue
end
2021-09-04 01:27:46 +05:30
def resolve_user_todos_for(discussion)
return unless discussion.for_design?
TodoService.new.resolve_todos_for_target(discussion, current_user)
end
2020-06-23 00:09:42 +05:30
def first_discussion
@first_discussion ||= discussions.first
end
2017-08-17 22:00:37 +05:30
def merge_request
2020-06-23 00:09:42 +05:30
strong_memoize(:merge_request) do
first_discussion.noteable if first_discussion.for_merge_request?
end
end
def process_auto_merge
return unless merge_request
2020-10-24 23:57:45 +05:30
return unless @resolved_count > 0
2020-06-23 00:09:42 +05:30
return unless discussions_ready_to_merge?
AutoMergeProcessWorker.perform_async(merge_request.id)
2017-08-17 22:00:37 +05:30
end
2020-06-23 00:09:42 +05:30
def discussions_ready_to_merge?
merge_request.auto_merge_enabled? && merge_request.mergeable_discussions_state?
2017-08-17 22:00:37 +05:30
end
end
end