Skip to content

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

Screenshot_2022-10-12_at_5.52.28_PM

How to set up and validate locally

  1. Enable feature flag only_allow_merge_if_all_status_checks_passed
  2. Add status check on project https://docs.gitlab.com/ee/user/project/merge_requests/status_checks.html#add-or-update-a-status-check.
  3. Create a merge request.
  4. Enable project setting only_allow_merge_if_all_status_checks_passed using API PUT /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
       }'
  5. use API GET /api/v4/projects/:id to confirm setting value
  6. Update status check status using https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check.
  7. 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.

Related to #369859 (closed)

Edited by Harsimar Sandhu

Merge request reports