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

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

36 lines
1.2 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
module MergeRequests
class RetargetChainService < MergeRequests::BaseService
MAX_RETARGET_MERGE_REQUESTS = 4
def execute(merge_request)
# we can only retarget MRs that are targeting the same project
return unless merge_request.for_same_project? && merge_request.merged?
# find another merge requests that
# - as a target have a current source project and branch
other_merge_requests = merge_request.source_project
.merge_requests
.opened
.by_target_branch(merge_request.source_branch)
.preload_source_project
2021-04-29 21:17:54 +05:30
.limit(MAX_RETARGET_MERGE_REQUESTS)
2021-04-17 20:07:23 +05:30
other_merge_requests.find_each do |other_merge_request|
# Update only MRs on projects that we have access to
next unless can?(current_user, :update_merge_request, other_merge_request.source_project)
2023-07-09 08:55:56 +05:30
::MergeRequests::UpdateService.new(
project: other_merge_request.source_project,
current_user: current_user,
params: {
target_branch: merge_request.target_branch,
target_branch_was_deleted: true
}
).execute(other_merge_request)
2021-04-17 20:07:23 +05:30
end
end
end
end