Merge Request API does not considered skipped pipelines successful
Summary
When accepting a merge request, merging via the API, if the head pipeline is skipped the API will return a 405.
When a project is configured to allow skipped pipelines (Skipped pipelines are considered successful
)the UI will allow a merge request to be merged. The API, however, will return a 405 regardless of the setting.
Steps to reproduce
- New Project
- Settings > General > Merge checks: Set
Skipped pipelines are considered successful
- New Branch -> Commit [skip ci]
- Create Merge Request
- Attempt update via API results in a 405.
curl -k -X PUT -H "Private-Token: $TOKEN" -H "Content-Type: application/json" -d '{"merge_when_pipeline_succeeds":true}'
"https://gitlab/api/v4/projects/62/merge_requests/3/merge"
What is the current bug behavior?
Merge Request is not automatically merged, and 405 is returned as a result of the API call.
What is the expected correct behavior?
Allow merge if skipped, and allowing for skipped pipelines.
Relevant logs and/or screenshots
Possible fixes
It looks like the API is checking for both
https://gitlab.com/gitlab-org/gitlab/-/blob/v13.5.3-ee/lib/api/merge_requests.rb#L435
automatically_mergeable = automatically_mergeable?(merge_when_pipeline_succeeds, merge_request)
immediately_mergeable = immediately_mergeable?(merge_when_pipeline_succeeds, merge_request)
automatically_mergeable
will check the merge request mergeable_ci_state?
which does include check if allowed merge on skipped pipeline.
immediately_mergeable
pivots off of the pipeline success ignoring the project setting.
Workaround
The merge request can still be merged if the merge_when_pipeline_succeeds
isn't set in the API call.