diff options
Diffstat (limited to 'app/controllers/projects/merge_requests_controller.rb')
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 76 |
1 files changed, 21 insertions, 55 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index bdd614973b7..fcc6384e27c 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -34,6 +34,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController def show @note_counts = Note.where(commit_id: @merge_request.commits.map(&:id)). group(:commit_id).count + respond_to do |format| format.html format.diff { render text: @merge_request.to_diff(current_user) } @@ -43,16 +44,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController def diffs @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") - diff_line_count = Commit::diff_line_count(@merge_request.diffs) - @suppress_diff = Commit::diff_suppress?(@merge_request.diffs, diff_line_count) && !params[:force_show_diff] - @force_suppress_diff = Commit::diff_force_suppress?(@merge_request.diffs, diff_line_count) - respond_to do |format| format.html format.json { render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") } } @@ -60,54 +58,22 @@ class Projects::MergeRequestsController < Projects::ApplicationController end def new - params[:merge_request] ||= ActionController::Parameters.new( - source_project: @project - ) - - @merge_request = MergeRequest.new(merge_request_params) - @merge_request.source_project = @project unless @merge_request.source_project - @merge_request.target_project ||= (@project.forked_from_project || @project) - @target_branches = @merge_request.target_project.nil? ? [] : @merge_request.target_project.repository.branch_names - @merge_request.target_branch ||= @merge_request.target_project.default_branch - @source_project = @merge_request.source_project - - if @merge_request.target_branch && @merge_request.source_branch - compare_action = Gitlab::Satellite::CompareAction.new( - current_user, - @merge_request.target_project, - @merge_request.target_branch, - @merge_request.source_project, - @merge_request.source_branch - ) - - @compare_failed = false - @commits = compare_action.commits - - if @commits - @commits.map! { |commit| Commit.new(commit) } - @commit = @commits.first - else - # false value because failed to get commits from satellite - @commits = [] - @compare_failed = true - end - - @note_counts = Note.where(commit_id: @commits.map(&:id)). - group(:commit_id).count - - begin - @diffs = compare_action.diffs - @merge_request.title = @merge_request.source_branch.titleize.humanize - @target_project = @merge_request.target_project - @target_repo = @target_project.repository - - diff_line_count = Commit::diff_line_count(@diffs) - @suppress_diff = Commit::diff_suppress?(@diffs, diff_line_count) - @force_suppress_diff = @suppress_diff - rescue Gitlab::Satellite::BranchesWithoutParent - @error = "Selected branches have no common commit so they cannot be merged." - end - end + params[:merge_request] ||= ActionController::Parameters.new(source_project: @project) + @merge_request = MergeRequests::BuildService.new(project, current_user, merge_request_params).execute + + @target_branches = if @merge_request.target_project + @merge_request.target_project.repository.branch_names + else + [] + end + + @target_project = merge_request.target_project + @source_project = merge_request.source_project + @commits = @merge_request.compare_commits + @commit = @merge_request.compare_base_commit + @diffs = @merge_request.compare_diffs + @note_counts = Note.where(commit_id: @commits.map(&:id)). + group(:commit_id).count end def edit |