debian-mirror-gitlab/app/services/merge_requests/post_merge_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
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
2020-11-24 15:15:51 +05:30
include RemovesRefs
2021-03-11 19:13:27 +05:30
MAX_RETARGET_MERGE_REQUESTS = 4
2015-09-25 12:07:36 +05:30
def execute(merge_request)
2021-06-08 01:23:25 +05:30
return if merge_request.merged?
# Mark the merge request as merged, everything that happens afterwards is
# executed once
2018-11-08 19:23:39 +05:30
merge_request.mark_as_merged
2021-06-08 01:23:25 +05:30
2018-03-17 18:26:18 +05:30
create_event(merge_request)
2021-06-08 01:23:25 +05:30
todo_service.merge_merge_request(merge_request, current_user)
2021-03-08 18:12:59 +05:30
merge_request_activity_counter.track_merge_mr_action(user: current_user)
2021-06-08 01:23:25 +05:30
create_note(merge_request)
close_issues(merge_request)
2015-09-25 12:07:36 +05:30
notification_service.merge_mr(merge_request, current_user)
2021-03-08 18:12:59 +05:30
invalidate_cache_counts(merge_request, users: merge_request.assignees | merge_request.reviewers)
2018-03-17 18:26:18 +05:30
merge_request.update_project_counter_caches
2018-11-08 19:23:39 +05:30
delete_non_latest_diffs(merge_request)
2020-07-28 23:09:34 +05:30
cancel_review_app_jobs!(merge_request)
2019-07-07 11:18:12 +05:30
cleanup_environments(merge_request)
2020-11-24 15:15:51 +05:30
cleanup_refs(merge_request)
2021-06-08 01:23:25 +05:30
execute_hooks(merge_request, 'merge')
2015-09-25 12:07:36 +05:30
end
private
2015-10-24 18:46:33 +05:30
def close_issues(merge_request)
return unless merge_request.target_branch == project.default_branch
2018-11-18 11:00:15 +05:30
closed_issues = merge_request.visible_closing_issues_for(current_user)
2016-08-24 12:49:21 +05:30
2015-10-24 18:46:33 +05:30
closed_issues.each do |issue|
2022-07-16 23:28:13 +05:30
# We are intentionally only closing Issues asynchronously (excluding ExternalIssues)
# as the worker only supports finding an Issue. We are also only experiencing
# SQL timeouts when closing an Issue.
2022-07-23 23:45:48 +05:30
if issue.is_a?(Issue)
2022-07-16 23:28:13 +05:30
MergeRequests::CloseIssueWorker.perform_async(
project.id,
current_user.id,
issue.id,
merge_request.id
)
else
2023-04-23 21:23:45 +05:30
Issues::CloseService.new(container: project, current_user: current_user).execute(issue, commit: merge_request)
2022-07-16 23:28:13 +05:30
end
2015-10-24 18:46:33 +05:30
end
end
2018-11-08 19:23:39 +05:30
def delete_non_latest_diffs(merge_request)
DeleteNonLatestDiffsService.new(merge_request).execute
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
2018-03-17 18:26:18 +05:30
def create_event(merge_request)
# Making sure MergeRequest::Metrics updates are in sync with
# Event creation.
Event.transaction do
merge_event = create_merge_event(merge_request, current_user)
merge_request_metrics_service(merge_request).merge(merge_event)
end
end
2015-09-25 12:07:36 +05:30
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
MergeRequests::PostMergeService.prepend_mod_with('MergeRequests::PostMergeService')