diff options
Diffstat (limited to 'app/controllers/projects/merge_requests_controller.rb')
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 33c1a1feff7..6c5285be0a2 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -24,8 +24,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController format.html format.js - format.diff { render text: @merge_request.to_diff } - format.patch { render text: @merge_request.to_patch } + format.diff { render text: @merge_request.to_diff(current_user) } + format.patch { render text: @merge_request.to_patch(current_user) } end end @@ -33,25 +33,39 @@ class Projects::MergeRequestsController < Projects::ApplicationController @commit = @merge_request.last_commit @comments_allowed = @reply_allowed = true - @comments_target = { noteable_type: 'MergeRequest', - noteable_id: @merge_request.id } + @comments_target = {noteable_type: 'MergeRequest', + noteable_id: @merge_request.id} @line_notes = @merge_request.notes.where("line_code is not null") end def new @merge_request = @project.merge_requests.new(params[:merge_request]) + + if params[:merge_request] && params[:merge_request][:source_project_id] + @merge_request.source_project = Project.find_by_id(params[:merge_request][:source_project_id]) + else + @merge_request.source_project = @project + end + if params[:merge_request] && params[:merge_request][:target_project_id] + @merge_request.target_project = Project.find_by_id(params[:merge_request][:target_project_id]) + end + @target_branches = @merge_request.target_project.nil? ? [] : @merge_request.target_project.repository.branch_names + @merge_request end def edit + @target_branches = @merge_request.target_project.repository.branch_names end def create @merge_request = @project.merge_requests.new(params[:merge_request]) @merge_request.author = current_user - + @merge_request.source_project_id = params[:merge_request][:source_project_id].to_i + @merge_request.target_project_id = params[:merge_request][:target_project_id].to_i + @target_branches ||= [] if @merge_request.save @merge_request.reload_code - redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' + redirect_to [@merge_request.target_project, @merge_request], notice: 'Merge request was successfully created.' else render "new" end @@ -89,22 +103,36 @@ class Projects::MergeRequestsController < Projects::ApplicationController end def branch_from + #This is always source @commit = @repository.commit(params[:ref]) end def branch_to - @commit = @repository.commit(params[:ref]) + @target_project = selected_target_project + @commit = @target_project.repository.commit(params[:ref]) end + def update_branches + @target_project = selected_target_project + @target_branches = (@target_project.repository.branch_names).unshift("Select branch") + @target_branches + end + + def ci_status status = project.gitlab_ci_service.commit_status(merge_request.last_commit.sha) - response = { status: status } + response = {status: status} render json: response end 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 + end + + def merge_request @merge_request ||= @project.merge_requests.find(params[:id]) end @@ -123,11 +151,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController def validates_merge_request # Show git not found page if target branch doesn't exist - return invalid_mr unless @project.repository.branch_names.include?(@merge_request.target_branch) + return invalid_mr unless @merge_request.target_project.repository.branch_names.include?(@merge_request.target_branch) # Show git not found page if source branch doesn't exist # and there is no saved commits between source & target branch - return invalid_mr if !@project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank? + return invalid_mr if !@merge_request.source_project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank? end def define_show_vars |