2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MergeRequests
|
|
|
|
class AfterCreateService < MergeRequests::BaseService
|
2022-01-26 12:08:38 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def execute(merge_request)
|
2023-01-13 00:05:48 +05:30
|
|
|
merge_request.ensure_merge_request_diff
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
execute_hooks(merge_request)
|
2022-04-04 11:22:00 +05:30
|
|
|
prepare_for_mergeability(merge_request)
|
2021-04-17 20:07:23 +05:30
|
|
|
prepare_merge_request(merge_request)
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
mark_merge_request_as_prepared(merge_request)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
def prepare_for_mergeability(merge_request)
|
|
|
|
create_pipeline_for(merge_request, current_user)
|
|
|
|
merge_request.update_head_pipeline
|
2022-04-04 11:22:00 +05:30
|
|
|
check_mergeability(merge_request)
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def prepare_merge_request(merge_request)
|
2020-04-08 14:13:33 +05:30
|
|
|
event_service.open_mr(merge_request, current_user)
|
2021-04-17 20:07:23 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
merge_request_activity_counter.track_create_mr_action(user: current_user, merge_request: merge_request)
|
2021-04-17 20:07:23 +05:30
|
|
|
merge_request_activity_counter.track_mr_including_ci_config(user: current_user, merge_request: merge_request)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
notification_service.new_merge_request(merge_request, current_user)
|
|
|
|
|
|
|
|
merge_request.diffs(include_stats: false).write_cache
|
|
|
|
merge_request.create_cross_references!(current_user)
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
Onboarding::ProgressService.new(merge_request.target_project.namespace).execute(action: :merge_request_created)
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_lfs_objects(merge_request)
|
2021-06-08 01:23:25 +05:30
|
|
|
LinkLfsObjectsService.new(project: merge_request.target_project).execute(merge_request)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
def check_mergeability(merge_request)
|
|
|
|
return unless merge_request.preparing?
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
# 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)
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
def mark_merge_request_as_prepared(merge_request)
|
|
|
|
merge_request.update!(prepared_at: Time.current)
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
MergeRequests::AfterCreateService.prepend_mod_with('MergeRequests::AfterCreateService')
|