Merge API `merge_when_pipeline_succeeds` behavior when pipeline has already failed
In the API endpoint for merging a MR, there is a
merge_when_pipeline_succeeds flag. If this endpoint is called with that attribute set to
true when the pipeline is still running then it works as expected - the MR is only merged if the pipeline succeeds.
However, if the endpoint is called when the pipeline has already failed, the MR is merged anyway.
At first glance this may be expected behavior, or at least acceptable behavior. The customer has identified what is essentially a race condition. Even if they first call the API to get the pipeline status and see that it's still running, it may fail before the subsequent
merge_when_pipeline_succeeds call arrives. Then the MR is merged when they wouldn't have wanted it to be.
Steps to reproduce
- Create a new project and add a dummy file
- Add a runner to the project
- Create a branch and add a .gitlab-ci.yml file that fails every time
- Create a merge request from this branch to master => The pipeline of the merge request is red
- Using the API accept the merge request with the parameter "merge_when_pipeline_succeeds=true" => The merge request is accepted whereas the pipeline failed