Commit fe2bfb45 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'add-mr-approvals-required-and-approvals-left-to-graphql' into 'master'

Expose approvals required and approvals left

See merge request gitlab-org/gitlab!42354
parents 0d5ce393 b4d85ef3
...@@ -9407,6 +9407,16 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -9407,6 +9407,16 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
allowCollaboration: Boolean 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. Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured.
""" """
......
...@@ -26108,6 +26108,34 @@ ...@@ -26108,6 +26108,34 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "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", "name": "approved",
"description": "Indicates if the merge request has all the required approvals. Returns true if no required approvals are configured.", "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. ...@@ -1416,6 +1416,8 @@ Autogenerated return type of MarkAsSpamSnippet.
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `allowCollaboration` | Boolean | Indicates if members of the target project can push to the fork | | `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. | | `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 | | `author` | User | User who created this merge request |
| `autoMergeEnabled` | Boolean! | Indicates if auto merge is enabled for the merge request | | `autoMergeEnabled` | Boolean! | Indicates if auto merge is enabled for the merge request |
......
...@@ -7,7 +7,11 @@ module EE ...@@ -7,7 +7,11 @@ module EE
prepended do prepended do
field :approved, GraphQL::BOOLEAN_TYPE, method: :approved?, null: false, 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.' 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, field :approved_by, ::Types::UserType.connection_type, null: true,
description: 'Users who approved the merge request' 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 ...@@ -49,4 +49,28 @@ RSpec.describe 'getting merge request listings (EE) nested in a project' do
include_examples 'N+1 query check' include_examples 'N+1 query check'
end 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 end
...@@ -32,6 +32,8 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do ...@@ -32,6 +32,8 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
if Gitlab.ee? if Gitlab.ee?
expected_fields << 'approved' expected_fields << 'approved'
expected_fields << 'approvals_left'
expected_fields << 'approvals_required'
expected_fields << 'approved_by' expected_fields << 'approved_by'
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