Backend should present a reason why a merge request is not mergeable

Problem

In BE, we have the method MergeRequest#mergeable?. This method check if the merge request is mergeable or not. For example, if an MR has not had enough approvals, the merge request is recongnized as un-mergeble state. Of course, this is not the only check, it could be with a pipeline state, git conflict, etc (and we would introduce more checks in the future).

In the meantime, FE shows a reason why user cannot merge the merge request, but they have own checking method to deduce the reason of why-its-not-mergeable. Most likely this logic is duplicated with BE's one, and thus either of them easily would be outdated, and actually, we had a situation that FE needs to patch some edge cases as their logic was not exactly the same with BE's corresponding one => https://gitlab.com/gitlab-org/gitlab-ce/issues/61371#note_166918493.

If we maintain those scattered mergeable logic wisely, we should not allow FE to guess that reason, but BE should provide the information to FE in the name of single source of truth.for this case.

Proposal

There are a couple of ideas:

  • BE adds unmergeable_reason attribute in MergeRequestWidgetEntity. FE renders the text if mergeable is false.
  • BE add a public/internal API endpoint GET merge_requests/:iid/mergeable. FE renders MR widget according to the result.

This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.

Edited Aug 10, 2022 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading