Fix GraphQL API mergeUser is null when mergeWhenPipelineSucceeds is false
What does this MR do and why?
Solves #321477 (closed)
GraphQL field mergeUser
is described in documentation as User who merged this merge request.
. However, it is only the user who set MR to Merge When Pipeline Succeeds. For merge request that merged without MWPS, it is nil.
This MR fixes that, so that this field is actually the user who merged the MR.
It will still return the user as soon as MWPS is set, for backwards compatibility. I've also clarified that fact in documentation.
The issue was that merge_request.merge_user
is actually only the user that set MWPS. When fetching the merged user, merge_request.metrics&.merged_by
should be used instead. For example, here it is used in REST API: https://gitlab.com/gitlab-org/gitlab/-/blob/6b591ca23013381a7c4a84f47691b91216911811/lib/api/entities/merge_request_basic.rb#L7
Alternative fix would be to keep mergeUser
as it is, and add a separate field, like mergedBy
, but I think that it would be a less intuitive option.
Screenshots or screen recordings
Before:
After:
How to set up and validate locally
- Create two MRs in a project with a pipeline.
- Merge one normally, and one by setting it to MWPS before the pipeline succeeds.
- Use following GraphQL query, after changing
fullPath
to your test project:
{
project(fullPath: "flightjs/Flight") {
name,
mergeRequests {
nodes {
id,
iid,
title,
mergeWhenPipelineSucceeds,
mergeUser {
name
}
}
}
}
}
After my changes both MR should have valid mergeUser
set. Before, only the MR merged using MWPS would have non-null mergeUser
.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.