Commit 71479a3f authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ph/fixMRGraphQlCommitsCount' into 'master'

Fixes GraphQl merge request types commits count

See merge request gitlab-org/gitlab!52218
parents fd2327ff 1ce97e7b
......@@ -152,7 +152,7 @@ module Types
end
field :task_completion_status, Types::TaskCompletionStatus, null: false,
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'
field :conflicts, GraphQL::BOOLEAN_TYPE, null: false, method: :cannot_be_merged?,
description: 'Indicates if the merge request has conflicts'
......@@ -218,10 +218,6 @@ module Types
BatchLoaders::MergeRequestDiffSummaryBatchLoader.load_for(object)
end
def commit_count
object&.metrics&.commits_count
end
def source_branch_protected
object.source_project.present? && ProtectedBranch.protected?(object.source_project, object.source_branch)
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
end
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
merge_request_a.metrics.update!(commits_count: 5)
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
include_examples 'N+1 query check'
end
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