summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2018-07-04 12:34:41 -0300
committerFelipe Artur <felipefac@gmail.com>2018-07-04 12:34:41 -0300
commit6d41df507143f87e33f335bc8c405a006a7f8a8d (patch)
tree054f21647b480638d7497b6e4f7f814c0fb9064b
parentd66bbf82b31b60c26646955c61e6a934b89d8a69 (diff)
downloadgitlab-ce-6d41df507143f87e33f335bc8c405a006a7f8a8d.tar.gz
Render LegacyDiffNote when diff_file blob is nil
-rw-r--r--app/serializers/diff_file_entity.rb5
-rw-r--r--lib/gitlab/diff/file.rb1
-rw-r--r--spec/serializers/diff_file_entity_spec.rb14
3 files changed, 20 insertions, 0 deletions
diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb
index aa289a96975..61135fba97b 100644
--- a/app/serializers/diff_file_entity.rb
+++ b/app/serializers/diff_file_entity.rb
@@ -25,6 +25,8 @@ class DiffFileEntity < Grape::Entity
expose :can_modify_blob do |diff_file|
merge_request = options[:merge_request]
+ next unless diff_file.blob
+
if merge_request&.source_project && current_user
can_modify_blob?(diff_file.blob, merge_request.source_project, merge_request.source_branch)
else
@@ -108,6 +110,7 @@ class DiffFileEntity < Grape::Entity
project = merge_request.target_project
next unless project
+ next unless diff_file.content_sha
project_blob_path(project, tree_join(diff_file.content_sha, diff_file.new_path))
end
@@ -125,6 +128,8 @@ class DiffFileEntity < Grape::Entity
end
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))
end
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index 40bcfa20e7d..81b719090f8 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -247,6 +247,7 @@ module Gitlab
lines = highlighted_diff_lines
return if lines.empty?
+ return if blob.nil?
last_line = lines.last
diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb
index c4a6c117b76..00b2146dc86 100644
--- a/spec/serializers/diff_file_entity_spec.rb
+++ b/spec/serializers/diff_file_entity_spec.rb
@@ -25,6 +25,20 @@ describe DiffFileEntity do
:context_lines_path
)
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
context 'when there is no merge request' do