2020-03-06 16:07:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MergeRequests
|
|
|
|
class AfterCreateService < MergeRequests::BaseService
|
2021-12-03 07:10:23 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-03-06 16:07:59 -05:00
|
|
|
def execute(merge_request)
|
2022-02-07 13:16:03 -05:00
|
|
|
prepare_for_mergeability(merge_request)
|
2021-03-09 13:09:41 -05:00
|
|
|
prepare_merge_request(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-11-30 10:14:19 -05:00
|
|
|
def prepare_for_mergeability(merge_request)
|
|
|
|
create_pipeline_for(merge_request, current_user)
|
|
|
|
merge_request.update_head_pipeline
|
2022-01-28 19:14:30 -05:00
|
|
|
check_mergeability(merge_request)
|
2021-11-30 10:14:19 -05:00
|
|
|
end
|
|
|
|
|
2021-03-09 13:09:41 -05:00
|
|
|
def prepare_merge_request(merge_request)
|
2020-03-06 16:07:59 -05:00
|
|
|
event_service.open_mr(merge_request, current_user)
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
merge_request_activity_counter.track_create_mr_action(user: current_user)
|
2021-03-05 10:09:12 -05:00
|
|
|
merge_request_activity_counter.track_mr_including_ci_config(user: current_user, merge_request: merge_request)
|
|
|
|
|
2020-03-06 16:07:59 -05:00
|
|
|
notification_service.new_merge_request(merge_request, current_user)
|
|
|
|
|
|
|
|
merge_request.diffs(include_stats: false).write_cache
|
|
|
|
merge_request.create_cross_references!(current_user)
|
2020-12-07 10:09:49 -05:00
|
|
|
|
2021-01-11 07:10:41 -05:00
|
|
|
OnboardingProgressService.new(merge_request.target_project.namespace).execute(action: :merge_request_created)
|
2021-04-01 05:09:05 -04:00
|
|
|
|
|
|
|
todo_service.new_merge_request(merge_request, current_user)
|
|
|
|
merge_request.cache_merge_request_closes_issues!(current_user)
|
|
|
|
|
|
|
|
Gitlab::UsageDataCounters::MergeRequestCounter.count(:create)
|
|
|
|
link_lfs_objects(merge_request)
|
2021-04-08 14:09:32 -04:00
|
|
|
|
|
|
|
delete_milestone_total_merge_requests_counter_cache(merge_request.milestone)
|
2021-04-01 05:09:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_lfs_objects(merge_request)
|
2021-05-11 23:10:21 -04:00
|
|
|
LinkLfsObjectsService.new(project: merge_request.target_project).execute(merge_request)
|
2020-03-06 16:07:59 -05:00
|
|
|
end
|
2021-11-30 10:14:19 -05:00
|
|
|
|
2022-01-28 19:14:30 -05:00
|
|
|
def check_mergeability(merge_request)
|
|
|
|
return unless merge_request.preparing?
|
|
|
|
|
|
|
|
# Need to set to unchecked to be able to check for mergeability or else
|
|
|
|
# it'll be a no-op.
|
|
|
|
merge_request.mark_as_unchecked
|
|
|
|
merge_request.check_mergeability(async: true)
|
2021-11-30 10:14:19 -05:00
|
|
|
end
|
2020-03-06 16:07:59 -05:00
|
|
|
end
|
|
|
|
end
|
2020-08-19 17:10:32 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
MergeRequests::AfterCreateService.prepend_mod_with('MergeRequests::AfterCreateService')
|