2015-08-11 08:33:31 -04:00
|
|
|
module MergeRequests
|
|
|
|
# PostMergeService class
|
|
|
|
#
|
|
|
|
# Mark existing merge request as merged
|
|
|
|
# and execute all hooks and notifications
|
|
|
|
#
|
|
|
|
class PostMergeService < MergeRequests::BaseService
|
|
|
|
def execute(merge_request)
|
2015-10-18 09:07:02 -04:00
|
|
|
close_issues(merge_request)
|
2016-09-22 17:30:37 -04:00
|
|
|
todo_service.merge_merge_request(merge_request, current_user)
|
2015-08-11 08:33:31 -04:00
|
|
|
merge_request.mark_as_merged
|
|
|
|
create_merge_event(merge_request, current_user)
|
|
|
|
create_note(merge_request)
|
|
|
|
notification_service.merge_mr(merge_request, current_user)
|
|
|
|
execute_hooks(merge_request, 'merge')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-10-18 09:07:02 -04:00
|
|
|
def close_issues(merge_request)
|
|
|
|
return unless merge_request.target_branch == project.default_branch
|
|
|
|
|
|
|
|
closed_issues = merge_request.closes_issues(current_user)
|
2016-07-06 09:26:59 -04:00
|
|
|
|
2015-10-18 09:07:02 -04:00
|
|
|
closed_issues.each do |issue|
|
2016-03-03 08:19:27 -05:00
|
|
|
if can?(current_user, :update_issue, issue)
|
2016-03-17 04:54:16 -04:00
|
|
|
Issues::CloseService.new(project, current_user, {}).execute(issue, commit: merge_request)
|
2016-03-03 08:19:27 -05:00
|
|
|
end
|
2015-10-18 09:07:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def create_merge_event(merge_request, current_user)
|
|
|
|
EventCreateService.new.merge_mr(merge_request, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|