Skip to content

Ensure merge request is fully prepared before checking its mergeability

Background

In #214742 (closed), it was found out that we are checking mergeability even if the pipeline wasn't created yet.

The pipeline is being created asynchronously so it's possible that the mergeability check happens before it and marks the merge request as mergeable which is not accurate.

Proposal

  1. Add a new preparing state to MergeRequest#merge_status state machine.
  2. Set merge_status to preparing on merge request creation (in MergeRequests#CreateService).
  3. Set merge_status to unchecked when fully prepared (in MergeRequests::AfterCreateService). This means that all preparations are done.
  4. Ensure that MergeRequest#mergeable? will always return false when merge_status is still preparing.

NOTE: We need to ensure that we transition states correctly to avoid having stale states that could lead to bugs.