Commit fcbe226f authored by Patrick Bajao's avatar Patrick Bajao

Update closed MRs on push

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/29420,
we started filtering the branches that we update on push. It only
looks at branches with open MRs.

It caused a regression wherein closed MRs approvals weren't being
reset even when `reset_approvals_on_push` setting is set to `true`.

This updates the `MergeRequests::PushedBranchesService` to include
closed MRs with matching source branches as well.
parent 2d7b2eef
...@@ -9,7 +9,7 @@ module MergeRequests ...@@ -9,7 +9,7 @@ module MergeRequests
def execute def execute
return [] if branch_names.blank? return [] if branch_names.blank?
source_branches = project.source_of_merge_requests.opened source_branches = project.source_of_merge_requests.open_and_closed
.from_source_branches(branch_names).pluck(:source_branch) .from_source_branches(branch_names).pluck(:source_branch)
target_branches = project.merge_requests.opened target_branches = project.merge_requests.opened
......
---
title: Update closed MRs on push
merge_request: 37414
author:
type: fixed
...@@ -8,19 +8,24 @@ RSpec.describe MergeRequests::PushedBranchesService do ...@@ -8,19 +8,24 @@ RSpec.describe MergeRequests::PushedBranchesService do
context 'when branches pushed' do context 'when branches pushed' do
let(:pushed_branches) do let(:pushed_branches) do
%w(branch1 branch2 extra1 extra2 extra3).map do |branch| %w(branch1 branch2 closed-branch1 closed-branch2 extra1 extra2).map do |branch|
{ ref: "refs/heads/#{branch}" } { ref: "refs/heads/#{branch}" }
end end
end end
it 'returns only branches which have a merge request' do it 'returns only branches which have a open and closed merge request' do
create(:merge_request, source_branch: 'branch1', source_project: project) create(:merge_request, source_branch: 'branch1', source_project: project)
create(:merge_request, source_branch: 'branch2', source_project: project) create(:merge_request, source_branch: 'branch2', source_project: project)
create(:merge_request, target_branch: 'branch2', source_project: project) create(:merge_request, target_branch: 'branch2', source_project: project)
create(:merge_request, :closed, target_branch: 'extra1', source_project: project) create(:merge_request, :closed, target_branch: 'closed-branch1', source_project: project)
create(:merge_request, source_branch: 'extra2') create(:merge_request, :closed, source_branch: 'closed-branch2', source_project: project)
create(:merge_request, source_branch: 'extra1')
expect(service.execute).to contain_exactly('branch1', 'branch2')
expect(service.execute).to contain_exactly(
'branch1',
'branch2',
'closed-branch2'
)
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