Fix bug with merge request branch select
Merge request target branch select is broken if you submit form and have some errors on page Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
9e181d36ea
commit
f416b2f5cf
3 changed files with 27 additions and 4 deletions
|
@ -60,7 +60,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
@merge_request = MergeRequest.new(params[:merge_request])
|
||||
@merge_request.source_project = @project unless @merge_request.source_project
|
||||
@merge_request.target_project = @project unless @merge_request.target_project
|
||||
@target_branches = @merge_request.target_project.nil? ? [] : @merge_request.target_project.repository.branch_names
|
||||
@source_project = @merge_request.source_project
|
||||
@merge_request
|
||||
end
|
||||
|
@ -167,7 +166,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
protected
|
||||
|
||||
def selected_target_project
|
||||
((@project.id.to_s == params[:target_project_id]) || @project.forked_project_link.nil?) ? @project : @project.forked_project_link.forked_from_project
|
||||
if @project.id.to_s == params[:target_project_id] || @project.forked_project_link.nil?
|
||||
@project
|
||||
else
|
||||
@project.forked_project_link.forked_from_project
|
||||
end
|
||||
end
|
||||
|
||||
def merge_request
|
||||
|
|
|
@ -253,4 +253,24 @@ class MergeRequest < ActiveRecord::Base
|
|||
message << description.to_s
|
||||
message
|
||||
end
|
||||
|
||||
# Return array of possible target branches
|
||||
# dependes on target project of MR
|
||||
def target_branches
|
||||
if target_project.nil?
|
||||
[]
|
||||
else
|
||||
target_project.repository.branch_names
|
||||
end
|
||||
end
|
||||
|
||||
# Return array of possible source branches
|
||||
# dependes on source project of MR
|
||||
def source_branches
|
||||
if source_project.nil?
|
||||
[]
|
||||
else
|
||||
source_project.repository.branch_names
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
= f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2 span3', disabled: @merge_request.persisted? })
|
||||
.pull-left
|
||||
|
||||
= f.select(:source_branch, @merge_request.source_project.repository.branch_names, { include_blank: "Select branch" }, {class: 'source_branch select2 span2'})
|
||||
= f.select(:source_branch, @merge_request.source_branches, { include_blank: "Select branch" }, {class: 'source_branch select2 span2'})
|
||||
.mr_source_commit.prepend-top-10
|
||||
.col-md-2
|
||||
.merge-request-angle
|
||||
|
@ -25,7 +25,7 @@
|
|||
= f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace'), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted? })
|
||||
.pull-left
|
||||
|
||||
= f.select(:target_branch, @target_branches, { include_blank: "Select branch" }, {class: 'target_branch select2 span2'})
|
||||
= f.select(:target_branch, @merge_request.target_branches, { include_blank: "Select branch" }, {class: 'target_branch select2 span2'})
|
||||
.mr_target_commit.prepend-top-10
|
||||
|
||||
%hr
|
||||
|
|
Loading…
Reference in a new issue