Commit 1ce97e7b authored by Phil Hughes's avatar Phil Hughes Committed by Igor Drozdov

Fixes GraphQl merge request types commits count

Fixes an issue where sometimes the commits count
would return `null` instead of the correct value.
parent 5ea79380
...@@ -152,7 +152,7 @@ module Types ...@@ -152,7 +152,7 @@ module Types
end end
field :task_completion_status, Types::TaskCompletionStatus, null: false, field :task_completion_status, Types::TaskCompletionStatus, null: false,
description: Types::TaskCompletionStatus.description description: Types::TaskCompletionStatus.description
field :commit_count, GraphQL::INT_TYPE, null: true, field :commit_count, GraphQL::INT_TYPE, null: true, method: :commits_count,
description: 'Number of commits in the merge request' description: 'Number of commits in the merge request'
field :conflicts, GraphQL::BOOLEAN_TYPE, null: false, method: :cannot_be_merged?, field :conflicts, GraphQL::BOOLEAN_TYPE, null: false, method: :cannot_be_merged?,
description: 'Indicates if the merge request has conflicts' description: 'Indicates if the merge request has conflicts'
...@@ -218,10 +218,6 @@ module Types ...@@ -218,10 +218,6 @@ module Types
BatchLoaders::MergeRequestDiffSummaryBatchLoader.load_for(object) BatchLoaders::MergeRequestDiffSummaryBatchLoader.load_for(object)
end end
def commit_count
object&.metrics&.commits_count
end
def source_branch_protected def source_branch_protected
object.source_project.present? && ProtectedBranch.protected?(object.source_project, object.source_branch) object.source_project.present? && ProtectedBranch.protected?(object.source_project, object.source_branch)
end end
......
---
title: Fixes GraphQl merge request types commits count
merge_request: 52218
author:
type: fixed
...@@ -196,17 +196,18 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -196,17 +196,18 @@ RSpec.describe 'getting merge request listings nested in a project' do
end end
context 'when requesting `commit_count`' do context 'when requesting `commit_count`' do
let(:requested_fields) { [:commit_count] } let(:merge_request_with_commits) { create(:merge_request, source_project: project) }
let(:search_params) { { iids: [merge_request_a.iid.to_s, merge_request_with_commits.iid.to_s] } }
let(:requested_fields) { [:iid, :commit_count] }
it 'exposes `commit_count`' do it 'exposes `commit_count`' do
merge_request_a.metrics.update!(commits_count: 5)
execute_query execute_query
expect(results).to include(a_hash_including('commitCount' => 5)) expect(results).to match_array([
{ "iid" => merge_request_a.iid.to_s, "commitCount" => 0 },
{ "iid" => merge_request_with_commits.iid.to_s, "commitCount" => 29 }
])
end end
include_examples 'N+1 query check'
end end
context 'when requesting `merged_at`' do context 'when requesting `merged_at`' 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