Find branches in all projects in the fork network

This commit is contained in:
Bob Van Landuyt 2017-09-21 18:34:32 +02:00
parent 70716a1292
commit 7c00b53812
3 changed files with 25 additions and 3 deletions

View file

@ -120,10 +120,13 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap
end
def selected_target_project
if @project.id.to_s == params[:target_project_id] || @project.forked_project_link.nil?
if @project.id.to_s == params[:target_project_id] || !@project.forked?
@project
elsif params[:target_project_id].present?
MergeRequestTargetProjectFinder.new(current_user: current_user, source_project: @project)
.execute.find(params[:target_project_id])
else
@project.forked_project_link.forked_from_project
@project.forked_from_project
end
end
end

View file

@ -1,7 +1,7 @@
class MergeRequestTargetProjectFinder
attr_reader :current_user, :source_project
def initialize(current_user: nil, source_project:, params: {})
def initialize(current_user: nil, source_project:)
@current_user = current_user
@source_project = source_project
end

View file

@ -44,6 +44,25 @@ feature 'Creating a merge request from a fork', :js do
expect { click_button 'Submit merge request' }
.to change { target_project.merge_requests.reload.size }.by(1)
end
it 'updates the branches when selecting a new target project' do
target_project_member = target_project.owner
CreateBranchService.new(target_project, target_project_member)
.execute('a-brand-new-branch-to-test', 'master')
visit project_new_merge_request_path(source_project)
first('.js-target-project').click
find('.dropdown-target-project .dropdown-content a', text: target_project.full_path).click
wait_for_requests
first('.js-target-branch').click
within('.dropdown-target-branch .dropdown-content') do
expect(page).to have_content('a-brand-new-branch-to-test')
end
end
end
context 'creating to the source of a fork' do