Class: MergeRequests::UpdateAssigneesService
- Inherits:
-
UpdateService
- Object
- BaseContainerService
- IssuableBaseService
- BaseService
- UpdateService
- MergeRequests::UpdateAssigneesService
- Defined in:
- app/services/merge_requests/update_assignees_service.rb
Instance Attribute Summary
Attributes inherited from BaseContainerService
#container, #current_user, #group, #project
Instance Method Summary collapse
-
#execute(merge_request) ⇒ Object
a stripped down service that only does what it must to update the assignees, and knows that it does not have to check for other updates.
Methods inherited from UpdateService
#after_update, #close_service, #handle_changes, #handle_task_changes, #initialize, #reopen_service
Methods included from Gitlab::Utils::Override
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
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 ErrorLogger
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
Constructor Details
This class inherits a constructor from MergeRequests::UpdateService
Instance Method Details
#execute(merge_request) ⇒ Object
a stripped down service that only does what it must to update the assignees, and knows that it does not have to check for other updates. This saves a lot of queries for irrelevant things that cannot possibly change in the execution of this service.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/merge_requests/update_assignees_service.rb', line 9 def execute(merge_request) return merge_request unless current_user&.can?(:set_merge_request_metadata, merge_request) old_assignees = merge_request.assignees.to_a old_ids = old_assignees.map(&:id) new_ids = new_user_ids(merge_request, update_attrs[:assignee_ids], :assignees) return merge_request if merge_request.errors.any? return merge_request if new_ids.size != update_attrs[:assignee_ids].size return merge_request if old_ids.to_set == new_ids.to_set # no-change attrs = update_attrs.merge(assignee_ids: new_ids) merge_request.update(**attrs) return merge_request unless merge_request.valid? # Defer the more expensive operations (handle_assignee_changes) to the background MergeRequests::HandleAssigneesChangeService .new(project: project, current_user: current_user) .async_execute(merge_request, old_assignees, execute_hooks: true) merge_request end |