Commit 8a617d71 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Add a feature flag for MarkerRanges

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/324068
parent 2b68d4d3
---
name: introduce_marker_ranges
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55669
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/324068
milestone: '13.10'
type: development
group: group::source code
default_enabled: false
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
module Gitlab module Gitlab
module Diff module Diff
class Highlight class Highlight
attr_reader :diff_file, :diff_lines, :raw_lines, :repository attr_reader :diff_file, :diff_lines, :raw_lines, :repository, :project
delegate :old_path, :new_path, :old_sha, :new_sha, to: :diff_file, prefix: :diff delegate :old_path, :new_path, :old_sha, :new_sha, to: :diff_file, prefix: :diff
def initialize(diff_lines, repository: nil) def initialize(diff_lines, repository: nil)
@repository = repository @repository = repository
@project = repository&.project
if diff_lines.is_a?(Gitlab::Diff::File) if diff_lines.is_a?(Gitlab::Diff::File)
@diff_file = diff_lines @diff_file = diff_lines
...@@ -30,6 +31,12 @@ module Gitlab ...@@ -30,6 +31,12 @@ module Gitlab
if line_inline_diffs = inline_diffs[i] if line_inline_diffs = inline_diffs[i]
begin begin
# MarkerRange objects are converted to Ranges to keep the previous behavior
# Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/324068
if Feature.disabled?(:introduce_marker_ranges, project, default_enabled: :yaml)
line_inline_diffs = line_inline_diffs.map { |marker_range| marker_range.to_range }
end
rich_line = InlineDiffMarker.new(diff_line.text, rich_line).mark(line_inline_diffs) rich_line = InlineDiffMarker.new(diff_line.text, rich_line).mark(line_inline_diffs)
# This should only happen when the encoding of the diff doesn't # This should only happen when the encoding of the diff doesn't
# match the blob, which is a bug. But we shouldn't fail to render # match the blob, which is a bug. But we shouldn't fail to render
......
...@@ -20,6 +20,10 @@ module Gitlab ...@@ -20,6 +20,10 @@ module Gitlab
@mode = mode @mode = mode
end end
def to_range
Range.new(self.begin, self.end, self.exclude_end?)
end
attr_reader :mode attr_reader :mode
end end
end end
...@@ -55,6 +55,18 @@ RSpec.describe Gitlab::Diff::Highlight do ...@@ -55,6 +55,18 @@ RSpec.describe Gitlab::Diff::Highlight do
expect(subject[5].rich_text).to eq(code) expect(subject[5].rich_text).to eq(code)
end end
context 'when introduce_marker_ranges is false' do
before do
stub_feature_flags(introduce_marker_ranges: false)
end
it 'keeps the old bevavior (without mode classes)' do
code = %Q{+<span id="LC9" class="line" lang="ruby"> <span class="k">raise</span> <span class="no"><span class="idiff left">RuntimeError</span></span><span class="p"><span class="idiff">,</span></span><span class="idiff right"> </span><span class="s2">"System commands must be given as an array of strings"</span></span>\n}
expect(subject[5].rich_text).to eq(code)
end
end
context 'when no diff_refs' do context 'when no diff_refs' do
before do before do
allow(diff_file).to receive(:diff_refs).and_return(nil) allow(diff_file).to receive(:diff_refs).and_return(nil)
......
...@@ -27,6 +27,20 @@ RSpec.describe Gitlab::MarkerRange do ...@@ -27,6 +27,20 @@ RSpec.describe Gitlab::MarkerRange do
end end
end end
describe '#to_range' do
subject { marker_range.to_range }
it { is_expected.to eq(first..last) }
context 'when mode is provided' do
let(:mode) { :deletion }
it 'is omitted during transformation' do
is_expected.not_to respond_to(:mode)
end
end
end
describe '.from_range' do describe '.from_range' do
subject { described_class.from_range(range) } subject { described_class.from_range(range) }
......
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