diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-06 17:13:28 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-08 14:37:46 -0500 |
commit | 50eae640dbbfa42a42e8b6966bd739cfda3adabc (patch) | |
tree | 1471ce67569d038e64a7e6f616d0d24be945aab9 /app/controllers/projects | |
parent | f47b737456f848784fddb5958c3fa781d2ede2f1 (diff) | |
download | gitlab-ce-50eae640dbbfa42a42e8b6966bd739cfda3adabc.tar.gz |
Fix specs and make tweaks
Diffstat (limited to 'app/controllers/projects')
-rwxr-xr-x | app/controllers/projects/merge_requests_controller.rb | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index bba3e007610..c25d33e12cf 100755 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -100,39 +100,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController respond_to do |format| format.html { define_discussion_vars } format.json do - @merge_request_diff = - if params[:diff_id] - @merge_request.merge_request_diffs.viewable.find(params[:diff_id]) - else - @merge_request.merge_request_diff - end - + define_diff_vars define_diff_comment_vars - @merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff - @comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id } - - if params[:start_sha].present? - @start_sha = params[:start_sha] - @start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha } - - unless @start_version - @start_sha = @merge_request_diff.head_commit_sha - @start_version = @merge_request_diff - end - end - @environment = @merge_request.environments_for(current_user).last - @diff_notes_disabled = !@merge_request_diff.latest? || @start_sha - - @diffs = - if @start_sha - @merge_request_diff.compare_with(@start_sha).diffs(diff_options) - else - @merge_request_diff.diffs(diff_options) - end - render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") } end end @@ -144,16 +116,18 @@ class Projects::MergeRequestsController < Projects::ApplicationController def diff_for_path if params[:id] merge_request + define_diff_vars define_diff_comment_vars else build_merge_request + @diffs = @merge_request.diffs(diff_options) @diff_notes_disabled = true @grouped_diff_discussions = {} end define_commit_vars - render_diff_for_path(@merge_request.diffs(diff_options)) + render_diff_for_path(@diffs) end def commits @@ -590,12 +564,43 @@ class Projects::MergeRequestsController < Projects::ApplicationController @base_commit = @merge_request.diff_base_commit || @merge_request.likely_diff_base_commit end + def define_diff_vars + @merge_request_diff = + if params[:diff_id] + @merge_request.merge_request_diffs.viewable.find(params[:diff_id]) + else + @merge_request.merge_request_diff + end + + @merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff + @comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id } + + if params[:start_sha].present? + @start_sha = params[:start_sha] + @start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha } + + unless @start_version + @start_sha = @merge_request_diff.head_commit_sha + @start_version = @merge_request_diff + end + end + + @diffs = + if @start_sha + @merge_request_diff.compare_with(@start_sha).diffs(diff_options) + else + @merge_request_diff.diffs(diff_options) + end + end + def define_diff_comment_vars @new_diff_note_attrs = { noteable_type: 'MergeRequest', noteable_id: @merge_request.id } + @diff_notes_disabled = !@merge_request_diff.latest? || @start_sha + @use_legacy_diff_notes = !@merge_request.has_complete_diff_refs? @grouped_diff_discussions = @merge_request.grouped_diff_discussions(@merge_request_diff.diff_refs) |