Commit cd83db4c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'do-not-refresh-main-when-fork-target-branch-updated' into 'master'

Do not reload diff for merge request made from fork when target branch in fork is updated

Closes #25263

See merge request !7973
parents 192d40e5 9190cea2
......@@ -101,7 +101,9 @@ class MergeRequest < ActiveRecord::Base
validate :validate_branches, unless: [:allow_broken, :importing?, :closed_without_fork?]
validate :validate_fork, unless: :closed_without_fork?
scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) }
scope :by_source_or_target_branch, ->(branch_name) do
where("source_branch = :branch OR target_branch = :branch", branch: branch_name)
end
scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) }
scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
scope :of_projects, ->(ids) { where(target_project_id: ids) }
......
......@@ -55,8 +55,9 @@ module MergeRequests
# Refresh merge request diff if we push to source or target branch of merge request
# Note: we should update merge requests from forks too
def reload_merge_requests
merge_requests = @project.merge_requests.opened.by_branch(@branch_name).to_a
merge_requests += fork_merge_requests.by_branch(@branch_name).to_a
merge_requests = @project.merge_requests.opened.
by_source_or_target_branch(@branch_name).to_a
merge_requests += fork_merge_requests
merge_requests = filter_merge_requests(merge_requests)
merge_requests.each do |merge_request|
......@@ -157,13 +158,14 @@ module MergeRequests
def merge_requests_for_source_branch
@source_merge_requests ||= begin
merge_requests = @project.origin_merge_requests.opened.where(source_branch: @branch_name).to_a
merge_requests += fork_merge_requests.where(source_branch: @branch_name).to_a
merge_requests += fork_merge_requests
filter_merge_requests(merge_requests)
end
end
def fork_merge_requests
@fork_merge_requests ||= @project.fork_merge_requests.opened
@fork_merge_requests ||= @project.fork_merge_requests.opened.
where(source_branch: @branch_name).to_a
end
def branch_added?
......
---
title: Do not reload diff for merge request made from fork when target branch in fork is updated
merge_request: 7973
author:
......@@ -126,6 +126,7 @@ describe MergeRequests::RefreshService, services: true do
end
context 'push to fork repo target branch' do
describe 'changes to merge requests' do
before do
service.new(@fork_project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
......@@ -139,6 +140,15 @@ describe MergeRequests::RefreshService, services: true do
it { expect(@fork_build_failed_todo).to be_pending }
end
describe 'merge request diff' do
it 'does not reload the diff of the merge request made from fork' do
expect do
service.new(@fork_project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
end.not_to change { @fork_merge_request.reload.merge_request_diff }
end
end
end
context 'push to origin repo target branch after fork project was removed' do
before do
@fork_project.destroy
......
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