Unify "merging" MR Widgets
What does this MR do?
For #324175 (closed)
This MR attempts to simplify a few different "merging" states into one unified component to display that state.
It does this by consolidating the following states to all display using the mr_widget_merging.vue
component:
- Merging: Auto-merge immediately —
ready_to_merge.vue
- Merging: Regular merge (not immediately) —
ready_to_merge.vue
- Merging —
mr_widget_merging.vue
Both of the former two are internal to the "Ready To Merge" component, triggered by user interaction on the ready component (e.g. click "Merge immediately").
The latter is when the MR loads already in that state, and shouldn't need to be modified except that it's now the same component as the other states.
Implementation Notes
The implementation found here can essentially be summed up as "Short Circuit Component Display In Certain States."
That is: for some of the existing cases, show a different component instead of the normal rendered content. Unfortunately dozens of state variables that mix together make it difficult to "carve out" the few small cases we want to exclude.
You'll note that the implementation in this MR adds a state machine.
In the code comments, I note that this new state machine is intended to replace all of it... eventually. After all, the widget can't be in multiple states at once, it must be reducible to a single state at a time.
However, I have to acknowledge that in the mean time, this does further increase the complexity: now there are all those dozens of state variables plus a state machine. The only saving grace - I hope - is that this is pretty removed: given a certain state machine value, the rest of the render logic need not apply.
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
Click the "Merge"
button on normal MRs to see the output if the merge will occur slowly enough for the normal polling update to occur, but this is unlikely.
The same output can also be seen when using the "Merge Immediately"
merge button when Merge Trains are enabled.
To see this output, enable Merge Trains on your instance (requires a Premium-tier license).
Add your test MR to a merge train, and then click "Merge Immediately".
In most cases, the default behavior (e.g. actually merging, polling overwriting local state) and the speed with which it happens is a roadblock to testing.
I use this patch to first make the polling and the merging inert. Then, I use these developer console commands to step the component through it's various stages:
1. Inert state
The MR is ready to merge.
var widget = document.querySelector( ".mr-widget-body" ).__vue__.$parent;
widget.mr.state = "readyToMerge";
2. "Merging" state
This is what happens when you click either the "Merge" or "Merge Immediately" buttons.
widget.mr.transitionStateMachine( { transition: "start-merge" } );
3. Failure
This is what happens when the merge fails after clicking merge.
Note: this view is missing most data because an actual failure would set various error data to the component, which this skips.
widget.mr.state = "mergeChecksFailed";
widget.mr.transitionStateMachine( { transition: "merge-failed" } );
4. Success
This is what happens after polling has resulted in a merged MR (or on a new pageload that starts with a merged state).
Note: this view is missing user information about who merged, because it skips the steps that would receive that info.
Note: If you've already moved to the failure state, get back to the "Merging" state by first setting the "1. Inert state" and then moving to the "Merging" (2.) state.
widget.mr.state = "merged";
widget.mr.transitionStateMachine( { transition: "merge-done" } );
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.