2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 14:51:17 -04:00
|
|
|
module MergeRequests
|
|
|
|
class ReopenService < MergeRequests::BaseService
|
|
|
|
def execute(merge_request)
|
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 merge_request.reopen
|
2017-12-07 12:41:30 -05:00
|
|
|
create_event(merge_request)
|
2017-07-19 10:03:50 -04:00
|
|
|
create_note(merge_request, 'reopened')
|
2018-04-20 13:37:38 -04:00
|
|
|
notification_service.async.reopen_mr(merge_request, current_user)
|
2015-01-17 19:34:34 -05:00
|
|
|
execute_hooks(merge_request, 'reopen')
|
2017-05-21 16:38:33 -04:00
|
|
|
merge_request.reload_diff(current_user)
|
2014-04-02 14:51:17 -04:00
|
|
|
merge_request.mark_as_unchecked
|
2017-07-11 12:12:33 -04:00
|
|
|
invalidate_cache_counts(merge_request, users: merge_request.assignees)
|
2017-10-30 12:20:29 -04:00
|
|
|
merge_request.update_project_counter_caches
|
2018-07-30 14:52:42 -04:00
|
|
|
merge_request.cache_merge_request_closes_issues!(current_user)
|
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
|
|
|
|
event_service.reopen_mr(merge_request, current_user)
|
|
|
|
merge_request_metrics_service(merge_request).reopen
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 14:51:17 -04:00
|
|
|
end
|
|
|
|
end
|