Class: MergeRequests::RequestReviewService

Inherits:
BaseService show all
Defined in:
app/services/merge_requests/request_review_service.rb

Instance Attribute Summary

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #deactivate_pages_deployments, #execute_external_hooks, #execute_group_mention_hooks, #execute_hooks, #handle_assignees_change, #handle_changes, #handle_reviewers_change, #hook_data, #initialize, #inspect, #merge_request_activity_counter, #source_project, #target_project

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from ErrorLogger

#log_error

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group, #root_ancestor

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from MergeRequests::BaseService

Instance Method Details

#execute(merge_request, user) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/merge_requests/request_review_service.rb', line 5

def execute(merge_request, user)
  return error("Invalid permissions") unless can?(current_user, :update_merge_request, merge_request)

  reviewer = merge_request.find_reviewer(user)

  if reviewer
    has_unapproved = remove_approval(merge_request, user).present?

    return error("Failed to update reviewer") unless reviewer.update(state: :unreviewed)

    notify_reviewer(merge_request, user)
    trigger_merge_request_merge_status_updated(merge_request)
    trigger_merge_request_reviewers_updated(merge_request)
    trigger_merge_request_approval_state_updated(merge_request)
    create_system_note(merge_request, user, has_unapproved)

    user.invalidate_merge_request_cache_counts if user.merge_request_dashboard_enabled?
    current_user.invalidate_merge_request_cache_counts if current_user.merge_request_dashboard_enabled?
    request_duo_code_review(merge_request) if user == ::Users::Internal.duo_code_review_bot

    success
  else
    error("Reviewer not found")
  end
end