Refresh auto-merge strategies on approval in MR widget

What does this MR do and why?

After a user approves a merge request, the merge request widget can show a stale Merge button for up to ~85 seconds instead of immediately offering the available auto-merge strategy.

Approving an MR changes mergeability, because :not_approved is one of the checks that available_strategies evaluates. However, availableAutoMergeStrategies only reaches the frontend in two ways:

  • The REST checkStatus poll, which starts at 5000ms and backs off exponentially (×1.2, capped around 245s), so it can be far away when the approval happens.
  • The GraphQL merge_request_merge_status_updated subscription, which the backend already triggers on approval (approval_service.rb:22).

The polled getState GraphQL query does not select availableAutoMergeStrategies, and the approve/unapprove action does not trigger a refresh itself. So when the subscription push doesn't reach the client, the widget is left waiting on the next backed-off poll. This was reported by a customer on GitLab.com who consistently saw the stale button for ~85 seconds.

This is a follow-up to !250480 (merged) (#593704 (closed)), which prevented the Merge button from rendering prematurely before auto-merge strategies loaded. This MR closes the related gap where the button also fails to update promptly after approval.

Fix: approvals.vue now emits an mr-widget-check-status eventHub event after a successful approve/unapprove. mr_widget_options.vue listens for this event and calls checkStatus, which performs the REST fetch and refreshes the available strategies within the 5-second throttle window, independent of the GraphQL subscription. This follows the existing eventHub pattern already used elsewhere in the widget.

Closes #629566 (closed).

How to set up and validate locally

  1. Open an MR that requires approval and has a running pipeline.
  2. Leave the widget open for a couple of minutes so the status poll backs off.
  3. Approve the MR.
  4. Confirm the Merge button updates to show the auto-merge option promptly, rather than waiting for the next poll cycle.

Run the relevant Jest specs:

node_modules/.bin/jest spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js

MR acceptance checklist

  • Tests added: approvals_spec.js asserts the mr-widget-check-status event is emitted after approval; mr_widget_options_spec.js asserts the event triggers a store data refresh. Verified RED before the fix, GREEN after.
  • Full merge request widget spec suite passes (CE and EE).
  • ESLint clean.
  • Frontend-only change; no feature flag or user-facing setting required.
  • Follows the existing eventHub pattern already used in the merge request widget.
Edited by Daniel Prause

Merge request reports

Loading
Loading