2015-09-25 12:07:36 +05:30
|
|
|
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-24 18:46:33 +05:30
|
|
|
close_issues(merge_request)
|
2016-11-03 12:29:30 +05:30
|
|
|
todo_service.merge_merge_request(merge_request, current_user)
|
2015-09-25 12:07:36 +05:30
|
|
|
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-24 18:46:33 +05:30
|
|
|
def close_issues(merge_request)
|
|
|
|
return unless merge_request.target_branch == project.default_branch
|
|
|
|
|
|
|
|
closed_issues = merge_request.closes_issues(current_user)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
closed_issues.each do |issue|
|
2016-06-02 11:05:42 +05:30
|
|
|
if can?(current_user, :update_issue, issue)
|
|
|
|
Issues::CloseService.new(project, current_user, {}).execute(issue, commit: merge_request)
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
def create_merge_event(merge_request, current_user)
|
|
|
|
EventCreateService.new.merge_mr(merge_request, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|