Commit b4d85ef3 authored by Adam Hegyi's avatar Adam Hegyi

Expose approvals required and approvals left

This change exposes merge request approvals required and approvals left
in the project merge requests GraphQL API.
parent 1d84b14b
......@@ -9407,6 +9407,16 @@ type MergeRequest implements CurrentUserTodos & Noteable {
"""
allowCollaboration: Boolean
"""
Number of approvals left
"""
approvalsLeft: Int
"""
Number of approvals required
"""
approvalsRequired: Int
"""
Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured.
"""
......
......@@ -26108,6 +26108,34 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "approvalsLeft",
"description": "Number of approvals left",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "approvalsRequired",
"description": "Number of approvals required",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "approved",
"description": "Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured.",
......@@ -1416,6 +1416,8 @@ Autogenerated return type of MarkAsSpamSnippet
| Field | Type | Description |
| ----- | ---- | ----------- |
| `allowCollaboration` | Boolean | Indicates if members of the target project can push to the fork |
| `approvalsLeft` | Int | Number of approvals left |
| `approvalsRequired` | Int | Number of approvals required |
| `approved` | Boolean! | Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured. |
| `author` | User | User who created this merge request |
| `autoMergeEnabled` | Boolean! | Indicates if auto merge is enabled for the merge request |
......
......@@ -8,6 +8,10 @@ module EE
prepended do
field :approved, GraphQL::BOOLEAN_TYPE, method: :approved?, null: false,
description: 'Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured.'
field :approvals_left, GraphQL::INT_TYPE, null: true,
description: 'Number of approvals left'
field :approvals_required, GraphQL::INT_TYPE, null: true,
description: 'Number of approvals required'
field :approved_by, ::Types::UserType.connection_type, null: true,
description: 'Users who approved the merge request'
......
---
title: Expose approvals required and approvals left for merge requests in GraphQL
merge_request: 42354
author:
type: changed
......@@ -49,4 +49,28 @@ RSpec.describe 'getting merge request listings (EE) nested in a project' do
include_examples 'N+1 query check'
end
context 'when requesting approval fields' do
let(:search_params) { { iids: [merge_request_a.iid.to_s] } }
let(:requested_fields) { [:approved, :approvals_left, :approvals_required] }
let(:approval_state) { instance_double(ApprovalState, approvals_required: 5, approvals_left: 3, approved?: false) }
before do
allow_next_found_instance_of(MergeRequest) do |mr|
allow(mr).to receive(:approval_state).and_return(approval_state)
end
end
it 'exposes approval metadata' do
execute_query
expect(results).to eq([
{
'approved' => false,
'approvalsLeft' => 3,
'approvalsRequired' => 5
}
])
end
end
end
......@@ -32,6 +32,8 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
if Gitlab.ee?
expected_fields << 'approved'
expected_fields << 'approvals_left'
expected_fields << 'approvals_required'
expected_fields << 'approved_by'
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