Commit 6d41df50 authored by Felipe Artur's avatar Felipe Artur

Render LegacyDiffNote when diff_file blob is nil

parent d66bbf82
...@@ -25,6 +25,8 @@ class DiffFileEntity < Grape::Entity ...@@ -25,6 +25,8 @@ class DiffFileEntity < Grape::Entity
expose :can_modify_blob do |diff_file| expose :can_modify_blob do |diff_file|
merge_request = options[:merge_request] merge_request = options[:merge_request]
next unless diff_file.blob
if merge_request&.source_project && current_user if merge_request&.source_project && current_user
can_modify_blob?(diff_file.blob, merge_request.source_project, merge_request.source_branch) can_modify_blob?(diff_file.blob, merge_request.source_project, merge_request.source_branch)
else else
...@@ -108,6 +110,7 @@ class DiffFileEntity < Grape::Entity ...@@ -108,6 +110,7 @@ class DiffFileEntity < Grape::Entity
project = merge_request.target_project project = merge_request.target_project
next unless project next unless project
next unless diff_file.content_sha
project_blob_path(project, tree_join(diff_file.content_sha, diff_file.new_path)) project_blob_path(project, tree_join(diff_file.content_sha, diff_file.new_path))
end end
...@@ -125,6 +128,8 @@ class DiffFileEntity < Grape::Entity ...@@ -125,6 +128,8 @@ class DiffFileEntity < Grape::Entity
end end
expose :context_lines_path, if: -> (diff_file, _) { diff_file.text? } do |diff_file| expose :context_lines_path, if: -> (diff_file, _) { diff_file.text? } do |diff_file|
next unless diff_file.content_sha
project_blob_diff_path(diff_file.repository.project, tree_join(diff_file.content_sha, diff_file.file_path)) project_blob_diff_path(diff_file.repository.project, tree_join(diff_file.content_sha, diff_file.file_path))
end end
......
...@@ -247,6 +247,7 @@ module Gitlab ...@@ -247,6 +247,7 @@ module Gitlab
lines = highlighted_diff_lines lines = highlighted_diff_lines
return if lines.empty? return if lines.empty?
return if blob.nil?
last_line = lines.last last_line = lines.last
......
...@@ -25,6 +25,20 @@ describe DiffFileEntity do ...@@ -25,6 +25,20 @@ describe DiffFileEntity do
:context_lines_path :context_lines_path
) )
end end
# Converted diff files from GitHub import does not contain blob file
# and content sha.
context 'when diff file does not have a blob and content sha' do
it 'exposes some attributes as nil' do
allow(diff_file).to receive(:content_sha).and_return(nil)
allow(diff_file).to receive(:blob).and_return(nil)
expect(subject[:context_lines_path]).to be_nil
expect(subject[:view_path]).to be_nil
expect(subject[:highlighted_diff_lines]).to be_nil
expect(subject[:can_modify_blob]).to be_nil
end
end
end end
context 'when there is no merge request' do context 'when there is no merge request' do
......
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