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
- Add a new
preparingstate toMergeRequest#merge_statusstate machine. - Set
merge_statustopreparingon merge request creation (inMergeRequests#CreateService). - Set
merge_statustouncheckedwhen fully prepared (inMergeRequests::AfterCreateService). This means that all preparations are done. - Ensure that
MergeRequest#mergeable?will always return false whenmerge_statusis stillpreparing.
NOTE: We need to ensure that we transition states correctly to avoid having stale states that could lead to bugs.