Commit b202b42c authored by Douwe Maan's avatar Douwe Maan

Link to outdated diff in older MR version from outdated diff discussion

parent 3d1cade1
...@@ -528,6 +528,8 @@ ...@@ -528,6 +528,8 @@
} }
.comments-disabled-notif { .comments-disabled-notif {
line-height: 28px;
.btn { .btn {
margin-left: 5px; margin-left: 5px;
} }
......
...@@ -16,7 +16,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -16,7 +16,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines] before_action :define_show_vars, only: [:show, :diffs, :commits, :conflicts, :conflict_for_path, :builds, :pipelines]
before_action :define_widget_vars, only: [:merge, :cancel_merge_when_pipeline_succeeds, :merge_check] before_action :define_widget_vars, only: [:merge, :cancel_merge_when_pipeline_succeeds, :merge_check]
before_action :define_commit_vars, only: [:diffs] before_action :define_commit_vars, only: [:diffs]
before_action :define_diff_comment_vars, only: [:diffs]
before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds, :conflicts, :conflict_for_path, :pipelines] before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds, :conflicts, :conflict_for_path, :pipelines]
before_action :close_merge_request_without_source_project, only: [:show, :diffs, :commits, :builds, :pipelines] before_action :close_merge_request_without_source_project, only: [:show, :diffs, :commits, :builds, :pipelines]
before_action :apply_diff_view_cookie!, only: [:new_diffs] before_action :apply_diff_view_cookie!, only: [:new_diffs]
...@@ -108,6 +107,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -108,6 +107,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request.merge_request_diff @merge_request.merge_request_diff
end end
define_diff_comment_vars
@merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff @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 } @comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id }
...@@ -123,10 +124,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -123,10 +124,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@environment = @merge_request.environments_for(current_user).last @environment = @merge_request.environments_for(current_user).last
@diff_notes_disabled = !@merge_request_diff.latest? || @start_sha
@diffs =
if @start_sha if @start_sha
compared_diff_version @merge_request_diff.compare_with(@start_sha).diffs(diff_options)
else else
original_diff_version @merge_request_diff.diffs(diff_options)
end end
render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") } render json: { html: view_to_html_string("projects/merge_requests/show/_diffs") }
...@@ -594,7 +598,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -594,7 +598,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@use_legacy_diff_notes = !@merge_request.has_complete_diff_refs? @use_legacy_diff_notes = !@merge_request.has_complete_diff_refs?
@grouped_diff_discussions = @merge_request.grouped_diff_discussions @grouped_diff_discussions = @merge_request.grouped_diff_discussions(@merge_request_diff.diff_refs)
@notes = prepare_notes_for_rendering(@grouped_diff_discussions.values.flatten.flat_map(&:notes)) @notes = prepare_notes_for_rendering(@grouped_diff_discussions.values.flatten.flat_map(&:notes))
end end
...@@ -678,16 +682,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -678,16 +682,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_request = MergeRequests::BuildService.new(project, current_user, merge_request_params.merge(diff_options: diff_options)).execute @merge_request = MergeRequests::BuildService.new(project, current_user, merge_request_params.merge(diff_options: diff_options)).execute
end end
def compared_diff_version
@diff_notes_disabled = true
@diffs = @merge_request_diff.compare_with(@start_sha).diffs(diff_options)
end
def original_diff_version
@diff_notes_disabled = !@merge_request_diff.latest?
@diffs = @merge_request_diff.diffs(diff_options)
end
def close_merge_request_without_source_project def close_merge_request_without_source_project
if !@merge_request.source_project && @merge_request.open? if !@merge_request.source_project && @merge_request.open?
@merge_request.close @merge_request.close
......
...@@ -25,4 +25,14 @@ module NoteOnDiff ...@@ -25,4 +25,14 @@ module NoteOnDiff
def diff_attributes def diff_attributes
raise NotImplementedError raise NotImplementedError
end end
private
def noteable_diff_refs
if noteable.respond_to?(:diff_sha_refs)
noteable.diff_sha_refs
else
noteable.diff_refs
end
end
end end
...@@ -36,10 +36,10 @@ module Noteable ...@@ -36,10 +36,10 @@ module Noteable
.discussions(self) .discussions(self)
end end
def grouped_diff_discussions def grouped_diff_discussions(*args)
# Doesn't use `discussion_notes`, because this may include commit diff notes # Doesn't use `discussion_notes`, because this may include commit diff notes
# besides MR diff notes, that we do no want to display on the MR Changes tab. # besides MR diff notes, that we do no want to display on the MR Changes tab.
notes.inc_relations_for_view.grouped_diff_discussions notes.inc_relations_for_view.grouped_diff_discussions(*args)
end end
def resolvable_discussions def resolvable_discussions
......
...@@ -10,6 +10,7 @@ class DiffDiscussion < Discussion ...@@ -10,6 +10,7 @@ class DiffDiscussion < Discussion
delegate :position, delegate :position,
:original_position, :original_position,
:latest_merge_request_diff,
to: :first_note to: :first_note
......
...@@ -65,20 +65,18 @@ class DiffNote < Note ...@@ -65,20 +65,18 @@ class DiffNote < Note
self.position.diff_refs == diff_refs self.position.diff_refs == diff_refs
end end
def latest_merge_request_diff
return unless for_merge_request?
self.noteable.merge_request_diff_for(self.position.diff_refs)
end
private private
def supported? def supported?
for_commit? || self.noteable.has_complete_diff_refs? for_commit? || self.noteable.has_complete_diff_refs?
end end
def noteable_diff_refs
if noteable.respond_to?(:diff_sha_refs)
noteable.diff_sha_refs
else
noteable.diff_refs
end
end
def set_original_position def set_original_position
self.original_position = self.position.dup unless self.original_position&.complete? self.original_position = self.position.dup unless self.original_position&.complete?
end end
......
...@@ -56,11 +56,12 @@ class LegacyDiffNote < Note ...@@ -56,11 +56,12 @@ class LegacyDiffNote < Note
# #
# If the note's current diff cannot be matched in the MergeRequest's current # If the note's current diff cannot be matched in the MergeRequest's current
# diff, it's considered inactive. # diff, it's considered inactive.
def active? def active?(diff_refs = nil)
return @active if defined?(@active) return @active if defined?(@active)
return true if for_commit? return true if for_commit?
return true unless diff_line return true unless diff_line
return false unless noteable return false unless noteable
return false if diff_refs && diff_refs != noteable_diff_refs
noteable_diff = find_noteable_diff noteable_diff = find_noteable_diff
......
...@@ -367,6 +367,10 @@ class MergeRequest < ActiveRecord::Base ...@@ -367,6 +367,10 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff(true) merge_request_diff(true)
end end
def merge_request_diff_for(diff_refs)
merge_request_diffs.viewable.select_without_diff.with_diff_refs(diff_refs).take
end
def reload_diff_if_branch_changed def reload_diff_if_branch_changed
if source_branch_changed? || target_branch_changed? if source_branch_changed? || target_branch_changed?
reload_diff reload_diff
......
...@@ -26,6 +26,7 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -26,6 +26,7 @@ class MergeRequestDiff < ActiveRecord::Base
end end
scope :viewable, -> { without_state(:empty) } scope :viewable, -> { without_state(:empty) }
scope :with_diff_refs, ->(diff_refs) { where(start_commit_sha: diff_refs.start_sha, head_commit_sha: diff_refs.head_sha, base_commit_sha: diff_refs.base_sha) }
# All diff information is collected from repository after object is created. # All diff information is collected from repository after object is created.
# It allows you to override variables like head_commit_sha before getting diff. # It allows you to override variables like head_commit_sha before getting diff.
......
...@@ -113,11 +113,11 @@ class Note < ActiveRecord::Base ...@@ -113,11 +113,11 @@ class Note < ActiveRecord::Base
Discussion.build(notes) Discussion.build(notes)
end end
def grouped_diff_discussions def grouped_diff_discussions(diff_refs = nil)
diff_notes. diff_notes.
fresh. fresh.
discussions. discussions.
select(&:active?). select { |n| n.active?(diff_refs) }.
group_by(&:line_code) group_by(&:line_code)
end end
...@@ -140,6 +140,10 @@ class Note < ActiveRecord::Base ...@@ -140,6 +140,10 @@ class Note < ActiveRecord::Base
true true
end end
def latest_merge_request_diff
nil
end
def max_attachment_size def max_attachment_size
current_application_settings.max_attachment_size.megabytes.to_i current_application_settings.max_attachment_size.megabytes.to_i
end end
......
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
on on
- if discussion.active? - if discussion.active?
= link_to 'the diff', discussion_diff_path(discussion) = link_to 'the diff', discussion_diff_path(discussion)
- else
- merge_request_diff = discussion.latest_merge_request_diff
- if merge_request_diff
= link_to diffs_namespace_project_merge_request_path(discussion.project.namespace, discussion.project, discussion.noteable, diff_id: merge_request_diff, anchor: discussion.line_code) do
an outdated diff
- else - else
an outdated diff an outdated diff
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
- left = line[:left] - left = line[:left]
- right = line[:right] - right = line[:right]
- last_line = right.new_pos if right - last_line = right.new_pos if right
- unless @diff_notes_disabled
- discussions_left, discussions_right = parallel_diff_discussions(left, right, diff_file) - discussions_left, discussions_right = parallel_diff_discussions(left, right, diff_file)
%tr.line_holder.parallel %tr.line_holder.parallel
- if left - if left
......
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
%a.show-suppressed-diff.js-show-suppressed-diff Changes suppressed. Click to show. %a.show-suppressed-diff.js-show-suppressed-diff Changes suppressed. Click to show.
%table.text-file.code.js-syntax-highlight{ data: diff_view_data, class: too_big ? 'hide' : '' } %table.text-file.code.js-syntax-highlight{ data: diff_view_data, class: too_big ? 'hide' : '' }
- discussions = @grouped_diff_discussions unless @diff_notes_disabled
= render partial: "projects/diffs/line", = render partial: "projects/diffs/line",
collection: diff_file.highlighted_diff_lines, collection: diff_file.highlighted_diff_lines,
as: :line, as: :line,
locals: { diff_file: diff_file, discussions: discussions } locals: { diff_file: diff_file, discussions: @grouped_diff_discussions }
- if !diff_file.new_file && !diff_file.deleted_file && diff_file.highlighted_diff_lines.any? - if !diff_file.new_file && !diff_file.deleted_file && diff_file.highlighted_diff_lines.any?
- last_line = diff_file.highlighted_diff_lines.last - last_line = diff_file.highlighted_diff_lines.last
......
...@@ -74,11 +74,13 @@ ...@@ -74,11 +74,13 @@
from from
%code= @merge_request.target_branch %code= @merge_request.target_branch
- unless @merge_request_diff.latest? && !@start_sha - if @diff_notes_disabled
.comments-disabled-notif.content-block .comments-disabled-notif.content-block
= icon('info-circle') = icon('info-circle')
- if @start_sha - if @start_sha
Comments are disabled because you're comparing two versions of this merge request. Comment creation is disabled because you're comparing two versions of this merge request.
- else - else
Comments are disabled because you're viewing an old version of this merge request. Discussions on this old version of the merge request are displayed but comment creation has been disabled.
.pull-right
= link_to 'Show latest version', diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: 'btn btn-sm' = link_to 'Show latest version', diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: 'btn btn-sm'
---
title: Link to outdated diff in older MR version from outdated diff discussion
merge_request:
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment