Commit 64975fd2 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '239090-fix-throughput-chart' into 'master'

Improve merge_request GraphQL endpoint

See merge request gitlab-org/gitlab!44613
parents 14f25d17 9cdc774c
...@@ -44,6 +44,7 @@ module ResolvesMergeRequests ...@@ -44,6 +44,7 @@ module ResolvesMergeRequests
author: [:author], author: [:author],
merged_at: [:metrics], merged_at: [:metrics],
commit_count: [:metrics], commit_count: [:metrics],
diff_stats_summary: [:metrics],
approved_by: [:approved_by_users], approved_by: [:approved_by_users],
milestone: [:milestone], milestone: [:milestone],
head_pipeline: [:merge_request_diff, { head_pipeline: [:merge_request] }] head_pipeline: [:merge_request_diff, { head_pipeline: [:merge_request] }]
......
...@@ -170,6 +170,12 @@ module Types ...@@ -170,6 +170,12 @@ module Types
end end
def diff_stats_summary def diff_stats_summary
metrics = object.metrics
if metrics && metrics.added_lines && metrics.removed_lines
return { additions: metrics.added_lines, deletions: metrics.removed_lines, file_count: object.merge_request_diff&.files_count || 0 }
end
nil_stats = { additions: 0, deletions: 0, file_count: 0 } nil_stats = { additions: 0, deletions: 0, file_count: 0 }
return nil_stats unless object.diff_stats.present? return nil_stats unless object.diff_stats.present?
......
---
title: Optionally use merge request metrics association for merge request diff stats
in GraphQL
merge_request: 44613
author:
type: performance
...@@ -38,4 +38,40 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do ...@@ -38,4 +38,40 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
expect(described_class).to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe '#diff_stats_summary' do
subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }
let(:current_user) { create :admin }
let(:query) do
%(
{
project(fullPath: "#{project.full_path}") {
mergeRequests {
nodes {
diffStatsSummary {
additions, deletions
}
}
}
}
}
)
end
let(:project) { create(:project, :public) }
let(:merge_request) { create(:merge_request, target_project: project, source_project: project) }
let(:response) { subject.dig('data', 'project', 'mergeRequests', 'nodes').first['diffStatsSummary'] }
context 'when MR metrics has additions and deletions' do
before do
merge_request.metrics.update!(added_lines: 5, removed_lines: 8)
end
it 'pulls out data from metrics object' do
expect(response).to match('additions' => 5, 'deletions' => 8)
end
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