Class: MergeRequests::CloseService

Inherits:
BaseService show all
Includes:
RemovesRefs
Defined in:
app/services/merge_requests/close_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from RemovesRefs

#cleanup_refs

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_hooks, #hook_data, #inspect, #source_project, #target_project

Methods included from Gitlab::Utils::Override

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

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

Methods inherited from BaseService

#initialize

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?

Instance Method Details

#execute(merge_request, commit = nil) ⇒ Object


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

def execute(merge_request, commit = nil)
  return merge_request unless can?(current_user, :update_merge_request, merge_request)

  # If we close MergeRequest we want to ignore validation
  # so we can close broken one (Ex. fork project removed)
  merge_request.allow_broken = true

  if merge_request.close
    create_event(merge_request)
    create_note(merge_request)
    notification_service.async.close_mr(merge_request, current_user)
    todo_service.close_merge_request(merge_request, current_user)
    execute_hooks(merge_request, 'close')
    invalidate_cache_counts(merge_request, users: merge_request.assignees)
    merge_request.update_project_counter_caches
    cleanup_environments(merge_request)
    abort_auto_merge(merge_request, 'merge request was closed')
    cleanup_refs(merge_request)
  end

  merge_request
end