Commit 5b70ffcf authored by Pavel Shutsin's avatar Pavel Shutsin

Add MergeRequestDiff#lines_count convenience method

parent 55320ff6
...@@ -196,6 +196,12 @@ class MergeRequestDiff < ApplicationRecord ...@@ -196,6 +196,12 @@ class MergeRequestDiff < ApplicationRecord
real_size.presence || raw_diffs.size real_size.presence || raw_diffs.size
end end
def lines_count
strong_memoize(:lines_count) do
diffs.diff_files.sum(&:line_count)
end
end
def raw_diffs(options = {}) def raw_diffs(options = {})
if options[:ignore_whitespace_change] if options[:ignore_whitespace_change]
@diffs_no_whitespace ||= compare.diffs(options) @diffs_no_whitespace ||= compare.diffs(options)
......
...@@ -235,6 +235,12 @@ MergeRequest::Metrics: ...@@ -235,6 +235,12 @@ MergeRequest::Metrics:
- latest_build_started_at - latest_build_started_at
- latest_build_finished_at - latest_build_finished_at
- first_deployed_to_production_at - first_deployed_to_production_at
- first_comment_at
- first_commit_at
- last_commit_at
- diff_size
- modified_paths_size
- commits_count
Ci::Pipeline: Ci::Pipeline:
- id - id
- project_id - project_id
......
...@@ -484,4 +484,12 @@ describe MergeRequestDiff do ...@@ -484,4 +484,12 @@ describe MergeRequestDiff do
end end
end end
end end
describe '#lines_count' do
subject { diff_with_commits }
it 'returns sum of all changed lines count in diff files' do
expect(subject.lines_count).to eq 109
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