Commit 2a72d498 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Unify app/services/merge_requests/refresh_service.rb

parent e5ef2d82
module MergeRequests
class RefreshService < MergeRequests::BaseService
prepend EE::MergeRequests::RefreshService
def execute(oldrev, newrev, ref)
return true unless Gitlab::Git.branch_ref?(ref)
......@@ -24,7 +26,6 @@ module MergeRequests
notify_about_push
mark_mr_as_wip_from_commits
execute_mr_web_hooks
reset_approvals_for_merge_requests
true
end
......@@ -97,22 +98,6 @@ module MergeRequests
merge_requests_for_source_branch(reload: true)
end
# Note: Closed merge requests also need approvals reset.
def reset_approvals_for_merge_requests
merge_requests = merge_requests_for(@branch_name, mr_states: [:opened, :closed])
merge_requests.each do |merge_request|
target_project = merge_request.target_project
if target_project.approvals_before_merge.nonzero? &&
target_project.reset_approvals_on_push &&
merge_request.rebase_commit_sha != @newrev
merge_request.approvals.delete_all
end
end
end
def reset_merge_when_pipeline_succeeds
merge_requests_for_source_branch.each(&:reset_merge_when_pipeline_succeeds)
end
......
module EE
module MergeRequests
module RefreshService
extend ::Gitlab::Utils::Override
override :execute
def execute(oldrev, newrev, ref)
return true unless ::Gitlab::Git.branch_ref?(ref)
super && reset_approvals_for_merge_requests(ref, newrev)
end
private
# Note: Closed merge requests also need approvals reset.
def reset_approvals_for_merge_requests(ref, newrev)
branch_name = ::Gitlab::Git.ref_name(ref)
merge_requests = merge_requests_for(branch_name, mr_states: [:opened, :closed])
merge_requests.each do |merge_request|
target_project = merge_request.target_project
if target_project.approvals_before_merge.nonzero? &&
target_project.reset_approvals_on_push &&
merge_request.rebase_commit_sha != newrev
merge_request.approvals.delete_all
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment