MergeTrain API failing with error `Branch has been updated since the merge was requested. Please review the changes. Try again`.
Summary
Customer attempted to utilize the MergeTrain API recently released to include a Merge Request (MR) in the merge train. However, the behavior of this API call was not consistent with the "Add to merge train" button in the user interface (UI).
When the UI button was used to add an MR to the merge train, it behaved as expected. Upon the successful completion of the MergeTrain pipeline, the MR was merged. However, when the API call was used to add the MR to the merge train, the MergeTrain pipeline ran, but the MR was subsequently rejected from the train with the following error message:
Branch has been updated since the merge was requested. Please review the changes. Try again.
Steps to reproduce
-
Create a Merge Request (MR) in GitLab for a branch that is part of the merge train pipeline.
-
Attempt to add the MR to the merge train via the API call using the following endpoint:
-
POST /projects/PROJECT-ID/merge_trains/merge_requests/MR-ID
-
Observe that the MergeTrain pipeline runs but the MR is subsequently rejected from the train with the following error message:
"Branch has been updated since the merge was requested. Please review the changes. Try again."
-
Compare this behavior with adding the MR to the merge train through the UI "Add to merge train" button.
-
Confirm that the MR is successfully merged when added via the UI button, but not when added via the API call.
Example Project
What is the current bug behavior?
What is the expected correct behavior?
The expected behavior is that when adding an MR to the merge train via the MergeTrain API call, it should behave in the same way as when adding it through the UI "Add to merge train" button.
This means that when the MergeTrain pipeline finishes successfully, the MR should be merged. However, based on the reported issue, the MergeTrain pipeline runs when the MR is added via the API call, but then it is rejected from the train with the error message "Branch has been updated since the merge was requested. Please review the changes. Try again."
Therefore, the expected behavior is for the API call to successfully add the MR to the merge train and for it to be merged upon the successful completion of the MergeTrain pipeline.
Relevant logs and/or screenshots
Instead of seeing the expected behavior, when attempting to add an MR to the merge train via the MergeTrain API call, the MR is rejected from the train with the error message "Branch has been updated since the merge was requested. Please review the changes. Try again."
The MergeTrain pipeline does run when the MR is added via the API call, but it fails to merge the MR upon completion. This is inconsistent with the behavior when adding an MR to the merge train through the UI "Add to merge train" button, which merges the MR upon successful completion of the MergeTrain pipeline.
Therefore, what we see instead is the unsuccessful addition of the MR to the merge train via the API call, with the pipeline running but ultimately failing to merge the MR.