Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5b1c6305
Commit
5b1c6305
authored
Oct 02, 2020
by
Pavel Kuznetsov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow get approvals on merge request by GraphQL in CE
parent
aa1dd6f5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
25 deletions
+35
-25
app/graphql/types/merge_request_type.rb
app/graphql/types/merge_request_type.rb
+7
-0
changelogs/unreleased/242285-approve-graphql-ce.yml
changelogs/unreleased/242285-approve-graphql-ce.yml
+5
-0
ee/app/graphql/ee/types/merge_request_type.rb
ee/app/graphql/ee/types/merge_request_type.rb
+0
-6
ee/spec/requests/api/graphql/project/merge_requests_spec.rb
ee/spec/requests/api/graphql/project/merge_requests_spec.rb
+0
-17
spec/graphql/types/merge_request_type_spec.rb
spec/graphql/types/merge_request_type_spec.rb
+1
-2
spec/requests/api/graphql/project/merge_requests_spec.rb
spec/requests/api/graphql/project/merge_requests_spec.rb
+22
-0
No files found.
app/graphql/types/merge_request_type.rb
View file @
5b1c6305
...
@@ -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
)
...
...
changelogs/unreleased/242285-approve-graphql-ce.yml
0 → 100644
View file @
5b1c6305
---
title
:
Allow get approvals on merge request by GraphQL in CE
author
:
Pavel Kuznetsov
merge_request
:
43325
type
:
add
ee/app/graphql/ee/types/merge_request_type.rb
View file @
5b1c6305
...
@@ -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
...
...
ee/spec/requests/api/graphql/project/merge_requests_spec.rb
View file @
5b1c6305
...
@@ -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
]
}
...
...
spec/graphql/types/merge_request_type_spec.rb
View file @
5b1c6305
...
@@ -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
)
...
...
spec/requests/api/graphql/project/merge_requests_spec.rb
View file @
5b1c6305
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment