Commit a65d4e2b authored by Piotr Stankowski's avatar Piotr Stankowski

Fix MergeRequest's MergeUser for non-MWPS merges in GraphQL API

Field MergeUser used to always be nil for merges done without
Merge When Pipeline Succeeds function, despite documentation
stating that it returns 'User who merged this merge request'.
I change it so that it works for MR without MWPS.
I've also clarified that mergeUser will be returned as soon
as MWPS is set, even before the merge actually happens.

Changelog: fixed
parent cffd45fa
......@@ -196,7 +196,7 @@ module Types
field :auto_merge_strategy, GraphQL::Types::String, null: true,
description: 'Selected auto merge strategy.'
field :merge_user, Types::UserType, null: true,
description: 'User who merged this merge request.'
description: 'User who merged this merge request or set it to merge when pipeline succeeds.'
field :timelogs, Types::TimelogType.connection_type, null: false,
description: 'Timelogs on the merge request.'
......@@ -268,6 +268,10 @@ module Types
def reviewers
object.reviewers
end
def merge_user
object.metrics&.merged_by || object.merge_user
end
end
end
......
......@@ -11698,7 +11698,7 @@ Maven metadata.
| <a id="mergerequestmergestatus"></a>`mergeStatus` **{warning-solid}** | [`String`](#string) | **Deprecated** in 14.0. This was renamed. Use: [`MergeRequest.mergeStatusEnum`](#mergerequestmergestatusenum). |
| <a id="mergerequestmergestatusenum"></a>`mergeStatusEnum` | [`MergeStatus`](#mergestatus) | Merge status of the merge request. |
| <a id="mergerequestmergetrainscount"></a>`mergeTrainsCount` | [`Int`](#int) | Number of merge requests in the merge train. |
| <a id="mergerequestmergeuser"></a>`mergeUser` | [`UserCore`](#usercore) | User who merged this merge request. |
| <a id="mergerequestmergeuser"></a>`mergeUser` | [`UserCore`](#usercore) | User who merged this merge request or set it to merge when pipeline succeeds. |
| <a id="mergerequestmergewhenpipelinesucceeds"></a>`mergeWhenPipelineSucceeds` | [`Boolean`](#boolean) | Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS). |
| <a id="mergerequestmergeable"></a>`mergeable` | [`Boolean!`](#boolean) | Indicates if the merge request is mergeable. |
| <a id="mergerequestmergeablediscussionsstate"></a>`mergeableDiscussionsState` | [`Boolean`](#boolean) | Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged. |
......@@ -133,4 +133,28 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
end
end
end
describe '#merge_user' do
let_it_be(:project) { create(:project, :public) }
context 'when MR is merged' do
let(:merge_request) { create(:merge_request, :with_merged_metrics, target_project: project, source_project: project) }
it 'is not nil' do
value = resolve_field(:merge_user, merge_request)
expect(value).not_to be_nil
end
end
context 'when MR is set to merge when pipeline succeeds' do
let(:merge_request) { create(:merge_request, :merge_when_pipeline_succeeds, target_project: project, source_project: project) }
it 'is not nil' do
value = resolve_field(:merge_user, merge_request)
expect(value).not_to be_nil
end
end
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