Only merge when all the status checks have passed
What does this MR do and why?
Add a new project-level setting to block merge requests from being merged unless status checks all passed. If enabled and status checks are failing / pending then merge requests should be blocked from merging. This MR does the backend work for this.
Screenshots or screen recordings
If status checks are pending/failed merging merge request should hide merge button
How to set up and validate locally
- Enable feature flag
only_allow_merge_if_all_status_checks_passed
- Add status check on project https://docs.gitlab.com/ee/user/project/merge_requests/status_checks.html#add-or-update-a-status-check.
- Create a merge request.
- Enable project setting
only_allow_merge_if_all_status_checks_passed
using APIPUT /api/v4/projects/:id
Sample curl curl --location --request PUT 'http://127.0.0.1:3000//api/v4/projects/9' \ --header 'Authorization: Bearer <your token>' \ --header 'Content-Type: application/json' \ --data-raw '{ "only_allow_merge_if_all_status_checks_passed": true }'
- use API
GET /api/v4/projects/:id
to confirm setting value - Update status check status using https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check.
- Merge request should raise error on merging unless all status checks are passed. (failed and pending status are both treated as blocking status)
Local Migration Logs
rake db:migrate:up:main VERSION=20220901114501
main: == 20220901114501 OnlyAllowMergeIfAllStatusChecksPassed: migrating ============
main: -- add_column(:project_settings, :only_allow_merge_if_all_status_checks_passed, :boolean, {:default=>false, :null=>false})
main: -> 0.0035s
main: == 20220901114501 OnlyAllowMergeIfAllStatusChecksPassed: migrated (0.0040s) ===
rake db:migrate:down:main VERSION=20220901114501
main: == 20220901114501 OnlyAllowMergeIfAllStatusChecksPassed: reverting ============
main: -- remove_column(:project_settings, :only_allow_merge_if_all_status_checks_passed, :boolean, {:default=>false, :null=>false})
main: -> 0.0020s
main: == 20220901114501 OnlyAllowMergeIfAllStatusChecksPassed: reverted (0.0034s) ===
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #369859 (closed)
Edited by Harsimar Sandhu