Ensure auto_merge_enabled is set when validating merge trains
What does this MR do and why?
Merge trains can get stuck if there is inconsistent state between the merge request and merge train.
This fix allows merge trains to recover from such inconsistent state the next time the train is refreshed. This, happens, for example, when a pipeline completes, and when a merge request is added or removed from the train. Corrected MRs will show two cancellation-related system notes: One for the original cancellation action that left the MR in an inconsistent state, and one for the merge train cleanup caused by the new validation being enforced.
See #500887 (closed)
References
Please include cross links to any resources that are relevant to this MR This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
How to set up and validate locally
Prepare a project with merge trains enabled.
In a rails console, prepare a service instance for the "wrong" kind of cancellation, to trigger the type of edge case this MR helps solve:
project = Project.find_by_full_path(YOUR_PROJECT_PATH)
user = User.first
mr = project.merge_requests.find_by_iid(YOUR_MR_IID)
service = AutoMerge::AddToMergeTrainWhenPipelineSucceedsService.new(project, user)
Then:
- Start a merge train on the MR (press Merge)
- Immediately after, run
service.cancel(mr.reload) - Start a merge train on another MR
- With this change, the second MR should get merged, and the first MR should get removed from the train
- Prior to this change, no MR on the train would get merged