Provide useful message along with 405 response on merge API endpoint
Zendesk: https://gitlab.zendesk.com/agent/tickets/119946
The Accept MR endpoint will return a 405 is the MR cannot be accepted at that time. There are a variety of reasons why this might happen, some of which are more temporary than others. As a result it would be helpful if there was a message or some additional feedback as to the nature of the problem so the caller can determine whether to wait and try again.
The 405 is returned at https://gitlab.com/gitlab-org/gitlab-ce/blob/913bc9649b012b178ef1acb9ef254fcc565be248/lib/api/merge_requests.rb#L378, which calls https://gitlab.com/gitlab-org/gitlab-ce/blob/913bc9649b012b178ef1acb9ef254fcc565be248/app/models/merge_request.rb#L756. This latter method is where all the conditions are set.
Some of them are less temporary, such as whether or not the MR is open. If it's closed, then the mergeability state is not likely to change by simply waiting. However, others like broken?
is more temporary. An MR can be considered broken if it has no commits or a branch is missing.
In the customer's use case they are creating a branch and pushing some changes immediately before creating an MR and merging it. This is done in such a rapid fire sequence that we theorize the PostReceive
job isn't finished and the MR appears broken
via the API.
It would be helpful if the caller had some indication that the branch was the issue and if they wait maybe it will become mergeable.
cc/ @kerrizor.