Commit badf7c34 authored by David Kim's avatar David Kim

Merge branch...

Merge branch '332883-bug-not-showing-warning-when-we-don-t-show-the-full-diff-in-a-merge-request' into 'master'

Resolve "Bug: Not showing warning when we don't show the full diff in a merge request"

See merge request gitlab-org/gitlab!64515
parents 74e339c1 791e1975
...@@ -190,10 +190,8 @@ module DiffHelper ...@@ -190,10 +190,8 @@ module DiffHelper
end end
def render_overflow_warning?(diffs_collection) def render_overflow_warning?(diffs_collection)
diff_files = diffs_collection.raw_diff_files diffs_collection.overflow?.tap do |overflown|
log_overflow_limits(diff_files: diffs_collection.raw_diff_files, collection_overflow: overflown)
diff_files.overflow?.tap do |overflown|
log_overflow_limits(diff_files)
end end
end end
...@@ -285,12 +283,12 @@ module DiffHelper ...@@ -285,12 +283,12 @@ module DiffHelper
conflicts_service.conflicts.files.index_by(&:our_path) conflicts_service.conflicts.files.index_by(&:our_path)
end end
def log_overflow_limits(diff_files) def log_overflow_limits(diff_files:, collection_overflow:)
if diff_files.any?(&:too_large?) if diff_files.any?(&:too_large?)
Gitlab::Metrics.add_event(:diffs_overflow_single_file_limits) Gitlab::Metrics.add_event(:diffs_overflow_single_file_limits)
end end
Gitlab::Metrics.add_event(:diffs_overflow_collection_limits) if diff_files.overflow? Gitlab::Metrics.add_event(:diffs_overflow_collection_limits) if collection_overflow
Gitlab::Metrics.add_event(:diffs_overflow_max_bytes_limits) if diff_files.overflow_max_bytes? Gitlab::Metrics.add_event(:diffs_overflow_max_bytes_limits) if diff_files.overflow_max_bytes?
Gitlab::Metrics.add_event(:diffs_overflow_max_files_limits) if diff_files.overflow_max_files? Gitlab::Metrics.add_event(:diffs_overflow_max_files_limits) if diff_files.overflow_max_files?
Gitlab::Metrics.add_event(:diffs_overflow_max_lines_limits) if diff_files.overflow_max_lines? Gitlab::Metrics.add_event(:diffs_overflow_max_lines_limits) if diff_files.overflow_max_lines?
......
...@@ -16,7 +16,6 @@ class MergeRequestDiffEntity < Grape::Entity ...@@ -16,7 +16,6 @@ class MergeRequestDiffEntity < Grape::Entity
end end
expose :created_at expose :created_at
expose :state
expose :commits_count expose :commits_count
expose :latest?, as: :latest expose :latest?, as: :latest
......
...@@ -85,6 +85,10 @@ module Gitlab ...@@ -85,6 +85,10 @@ module Gitlab
# No-op # No-op
end end
def overflow?
raw_diff_files.overflow?
end
private private
def empty_pagination_data def empty_pagination_data
......
...@@ -48,6 +48,10 @@ module Gitlab ...@@ -48,6 +48,10 @@ module Gitlab
@merge_request_diff.real_size @merge_request_diff.real_size
end end
def overflow?
@merge_request_diff.overflow?
end
private private
def highlight_cache def highlight_cache
......
...@@ -293,14 +293,14 @@ RSpec.describe DiffHelper do ...@@ -293,14 +293,14 @@ RSpec.describe DiffHelper do
describe '#render_overflow_warning?' do describe '#render_overflow_warning?' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:diffs_collection) { instance_double(Gitlab::Diff::FileCollection::MergeRequestDiff, raw_diff_files: diff_files) } let(:diffs_collection) { instance_double(Gitlab::Diff::FileCollection::MergeRequestDiff, raw_diff_files: diff_files, overflow?: false) }
let(:diff_files) { Gitlab::Git::DiffCollection.new(files) } let(:diff_files) { Gitlab::Git::DiffCollection.new(files) }
let(:safe_file) { { too_large: false, diff: '' } } let(:safe_file) { { too_large: false, diff: '' } }
let(:large_file) { { too_large: true, diff: '' } } let(:large_file) { { too_large: true, diff: '' } }
let(:files) { [safe_file, safe_file] } let(:files) { [safe_file, safe_file] }
context 'when no limits are hit' do
before do before do
allow(diff_files).to receive(:overflow?).and_return(false)
allow(diff_files).to receive(:overflow_max_bytes?).and_return(false) allow(diff_files).to receive(:overflow_max_bytes?).and_return(false)
allow(diff_files).to receive(:overflow_max_files?).and_return(false) allow(diff_files).to receive(:overflow_max_files?).and_return(false)
allow(diff_files).to receive(:overflow_max_lines?).and_return(false) allow(diff_files).to receive(:overflow_max_lines?).and_return(false)
...@@ -309,7 +309,6 @@ RSpec.describe DiffHelper do ...@@ -309,7 +309,6 @@ RSpec.describe DiffHelper do
allow(diff_files).to receive(:collapsed_safe_lines?).and_return(false) allow(diff_files).to receive(:collapsed_safe_lines?).and_return(false)
end end
context 'when no limits are hit' do
it 'returns false and does not log any overflow events' do it 'returns false and does not log any overflow events' do
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collection_limits) expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collection_limits)
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_single_file_limits) expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_single_file_limits)
...@@ -343,7 +342,7 @@ RSpec.describe DiffHelper do ...@@ -343,7 +342,7 @@ RSpec.describe DiffHelper do
context 'when the file collection has an overflow' do context 'when the file collection has an overflow' do
before do before do
allow(diff_files).to receive(:overflow?).and_return(true) allow(diffs_collection).to receive(:overflow?).and_return(true)
end end
it 'returns true and only logs all the correct collection overflow event' do it 'returns true and only logs all the correct collection overflow event' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Diff::FileCollection::Base do
let(:merge_request) { create(:merge_request) }
let(:diffable) { merge_request.merge_request_diff }
let(:diff_options) { {} }
describe '#overflow?' do
subject(:overflown) { described_class.new(diffable, project: merge_request.project, diff_options: diff_options).overflow? }
context 'when it is not overflown' do
it 'returns false' do
expect(overflown).to eq(false)
end
end
context 'when it is overflown' do
let(:diff_options) { { max_files: 1 } }
it 'returns true' do
expect(overflown).to eq(true)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBase do
let(:merge_request) { create(:merge_request) }
let(:diffable) { merge_request.merge_request_diff }
describe '#overflow?' do
subject(:overflown) { described_class.new(diffable, diff_options: nil).overflow? }
context 'when it is not overflown' do
it 'returns false' do
expect(overflown).to eq(false)
end
end
context 'when it is overflown' do
before do
diffable.update!(state: :overflow)
end
it 'returns true' do
expect(overflown).to eq(true)
end
end
end
end
...@@ -29,7 +29,7 @@ RSpec.describe MergeRequestDiffEntity do ...@@ -29,7 +29,7 @@ RSpec.describe MergeRequestDiffEntity do
expect(subject).to include( expect(subject).to include(
:version_index, :created_at, :commits_count, :version_index, :created_at, :commits_count,
:latest, :short_commit_sha, :version_path, :latest, :short_commit_sha, :version_path,
:compare_path, :state :compare_path
) )
end end
end end
......
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