Commit 5b1c6305 authored by Pavel Kuznetsov's avatar Pavel Kuznetsov

Allow get approvals on merge request by GraphQL in CE

parent aa1dd6f5
...@@ -152,6 +152,13 @@ module Types ...@@ -152,6 +152,13 @@ module Types
field :auto_merge_enabled, GraphQL::BOOLEAN_TYPE, null: false, field :auto_merge_enabled, GraphQL::BOOLEAN_TYPE, null: false,
description: 'Indicates if auto merge is enabled for the merge request' description: 'Indicates if auto merge is enabled for the merge request'
field :approved_by, Types::UserType.connection_type, null: true,
description: 'Users who approved the merge request'
def approved_by
object.approved_by_users
end
def diff_stats(path: nil) def diff_stats(path: nil)
stats = Array.wrap(object.diff_stats&.to_a) stats = Array.wrap(object.diff_stats&.to_a)
......
---
title: Allow get approvals on merge request by GraphQL in CE
author: Pavel Kuznetsov
merge_request: 43325
type: add
...@@ -12,12 +12,6 @@ module EE ...@@ -12,12 +12,6 @@ module EE
description: 'Number of approvals left' description: 'Number of approvals left'
field :approvals_required, GraphQL::INT_TYPE, null: true, field :approvals_required, GraphQL::INT_TYPE, null: true,
description: 'Number of approvals required' description: 'Number of approvals required'
field :approved_by, ::Types::UserType.connection_type, null: true,
description: 'Users who approved the merge request'
def approved_by
object.approved_by_users
end
end end
end end
end end
......
...@@ -33,23 +33,6 @@ RSpec.describe 'getting merge request listings (EE) nested in a project' do ...@@ -33,23 +33,6 @@ RSpec.describe 'getting merge request listings (EE) nested in a project' do
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
end end
context 'when requesting `approved_by`' do
let(:search_params) { { iids: [merge_request_a.iid.to_s, merge_request_b.iid.to_s] } }
let(:extra_iid_for_second_query) { merge_request_c.iid.to_s }
let(:requested_fields) { query_graphql_field(:approved_by, nil, query_graphql_field(:nodes, nil, [:username])) }
it 'exposes approver username' do
merge_request_a.approved_by_users << current_user
execute_query
user_data = { 'username' => current_user.username }
expect(results).to include(a_hash_including('approvedBy' => { 'nodes' => array_including(user_data) }))
end
include_examples 'N+1 query check'
end
context 'when requesting approval fields' do context 'when requesting approval fields' do
let(:search_params) { { iids: [merge_request_a.iid.to_s] } } let(:search_params) { { iids: [merge_request_a.iid.to_s] } }
let(:requested_fields) { [:approved, :approvals_left, :approvals_required] } let(:requested_fields) { [:approved, :approvals_left, :approvals_required] }
......
...@@ -27,14 +27,13 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do ...@@ -27,14 +27,13 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
upvotes downvotes head_pipeline pipelines task_completion_status upvotes downvotes head_pipeline pipelines task_completion_status
milestone assignees participants subscribed labels discussion_locked time_estimate milestone assignees participants subscribed labels discussion_locked time_estimate
total_time_spent reference author merged_at commit_count current_user_todos total_time_spent reference author merged_at commit_count current_user_todos
conflicts auto_merge_enabled conflicts auto_merge_enabled approved_by
] ]
if Gitlab.ee? if Gitlab.ee?
expected_fields << 'approved' expected_fields << 'approved'
expected_fields << 'approvals_left' expected_fields << 'approvals_left'
expected_fields << 'approvals_required' expected_fields << 'approvals_required'
expected_fields << 'approved_by'
end end
expect(described_class).to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
......
...@@ -172,6 +172,28 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -172,6 +172,28 @@ RSpec.describe 'getting merge request listings nested in a project' do
it_behaves_like 'searching with parameters' it_behaves_like 'searching with parameters'
end end
context 'when requesting `approved_by`' do
let(:search_params) { { iids: [merge_request_a.iid.to_s, merge_request_b.iid.to_s] } }
let(:extra_iid_for_second_query) { merge_request_c.iid.to_s }
let(:requested_fields) { query_graphql_field(:approved_by, nil, query_graphql_field(:nodes, nil, [:username])) }
def execute_query
query = query_merge_requests(requested_fields)
post_graphql(query, current_user: current_user)
end
it 'exposes approver username' do
merge_request_a.approved_by_users << current_user
execute_query
user_data = { 'username' => current_user.username }
expect(results).to include(a_hash_including('approvedBy' => { 'nodes' => array_including(user_data) }))
end
include_examples 'N+1 query check'
end
describe 'fields' do describe 'fields' do
let(:requested_fields) { nil } let(:requested_fields) { nil }
let(:extra_iid_for_second_query) { merge_request_c.iid.to_s } let(:extra_iid_for_second_query) { merge_request_c.iid.to_s }
......
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