2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 14:51:17 -04:00
|
|
|
module MergeRequests
|
|
|
|
class CloseService < MergeRequests::BaseService
|
|
|
|
def execute(merge_request, commit = nil)
|
2016-08-09 11:51:40 -04:00
|
|
|
return merge_request unless can?(current_user, :update_merge_request, merge_request)
|
|
|
|
|
2014-04-02 14:51:17 -04:00
|
|
|
# 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
|
2017-12-07 12:41:30 -05:00
|
|
|
create_event(merge_request)
|
2014-04-02 14:51:17 -04:00
|
|
|
create_note(merge_request)
|
2018-04-20 13:37:38 -04:00
|
|
|
notification_service.async.close_mr(merge_request, current_user)
|
2016-02-20 08:59:59 -05:00
|
|
|
todo_service.close_merge_request(merge_request, current_user)
|
2015-01-17 19:34:34 -05:00
|
|
|
execute_hooks(merge_request, 'close')
|
2017-07-11 12:12:33 -04:00
|
|
|
invalidate_cache_counts(merge_request, users: merge_request.assignees)
|
2017-09-19 07:55:56 -04:00
|
|
|
merge_request.update_project_counter_caches
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
merge_request
|
|
|
|
end
|
2017-12-07 12:41:30 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_event(merge_request)
|
|
|
|
# Making sure MergeRequest::Metrics updates are in sync with
|
|
|
|
# Event creation.
|
|
|
|
Event.transaction do
|
|
|
|
close_event = event_service.close_mr(merge_request, current_user)
|
|
|
|
merge_request_metrics_service(merge_request).close(close_event)
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|