Commit 0c25bb4d authored by David Kim's avatar David Kim Committed by Nick Thomas

Add file_identifier_hash to diff position

parent a5f6efc8
......@@ -6,6 +6,7 @@ module Gitlab
class BaseFormatter
attr_reader :old_path
attr_reader :new_path
attr_reader :file_identifier_hash
attr_reader :base_sha
attr_reader :start_sha
attr_reader :head_sha
......@@ -16,6 +17,7 @@ module Gitlab
attrs[:diff_refs] = diff_file.diff_refs
attrs[:old_path] = diff_file.old_path
attrs[:new_path] = diff_file.new_path
attrs[:file_identifier_hash] = diff_file.file_identifier_hash
end
if diff_refs = attrs[:diff_refs]
......@@ -26,6 +28,7 @@ module Gitlab
@old_path = attrs[:old_path]
@new_path = attrs[:new_path]
@file_identifier_hash = attrs[:file_identifier_hash]
@base_sha = attrs[:base_sha]
@start_sha = attrs[:start_sha]
@head_sha = attrs[:head_sha]
......@@ -36,7 +39,7 @@ module Gitlab
end
def to_h
{
out = {
base_sha: base_sha,
start_sha: start_sha,
head_sha: head_sha,
......@@ -44,6 +47,12 @@ module Gitlab
new_path: new_path,
position_type: position_type
}
if Feature.enabled?(:file_identifier_hash)
out[:file_identifier_hash] = file_identifier_hash
end
out
end
def position_type
......
......@@ -9,6 +9,7 @@ module Gitlab
delegate :old_path,
:new_path,
:file_identifier_hash,
:base_sha,
:start_sha,
:head_sha,
......
......@@ -10,6 +10,7 @@ describe Gitlab::Diff::Formatters::ImageFormatter do
head_sha: 789,
old_path: 'old_image.png',
new_path: 'new_image.png',
file_identifier_hash: '777',
position_type: 'image'
}
end
......
......@@ -10,6 +10,7 @@ describe Gitlab::Diff::Formatters::TextFormatter do
head_sha: 789,
old_path: 'old_path.txt',
new_path: 'new_path.txt',
file_identifier_hash: '777',
line_range: nil
}
end
......
......@@ -195,6 +195,10 @@ RSpec.configure do |config|
stub_feature_flags(flag => enable_rugged)
end
# Disable the usage of file_identifier_hash by default until it is ready
# See https://gitlab.com/gitlab-org/gitlab/-/issues/33867
stub_feature_flags(file_identifier_hash: false)
allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged)
end
......
......@@ -32,7 +32,21 @@ RSpec.shared_examples "position formatter" do
subject { formatter.to_h }
it { is_expected.to eq(formatter_hash) }
context 'when file_identifier_hash is disabled' do
before do
stub_feature_flags(file_identifier_hash: false)
end
it { is_expected.to eq(formatter_hash.except(:file_identifier_hash)) }
end
context 'when file_identifier_hash is enabled' do
before do
stub_feature_flags(file_identifier_hash: true)
end
it { is_expected.to eq(formatter_hash) }
end
end
describe '#==' 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