Skip to content

Add merge blocked message to status checks MR widget on pending/failed

Daniel Tian requested to merge 369861-status-check-merge-blocked-message into master

What does this MR do and why?

This MR adds a merge blocked message to the status check widget on the MR details page when at least one status check is either pending or failed. The message is not shown only when all the status checks have passed.

Pending/Failed Passed
ksnip_20221026-221448 ksnip_20221026-221411
Describe in detail what your merge request does and why.

How to set up and validate locally

  1. Enable the only_allow_merge_if_all_status_checks_passed feature flag.

  2. In your user settings, create a personal access token. We will need this to enable a feature that currently doesn't have a UI. For the scopes, check everything:

ksnip_20221026-102334
  1. Go to a project, Settings -> Merge requests, scroll down to Status checks, and click Add status check:
ksnip_20221026-101556
  1. In the Add status check modal, fill it out with any name and a fake URL for the API to check, then save it.

  2. There's no UI to enable the "enforce status checks passed" feature yet, so use this curl command to enable it for the project, replacing the <project id> and <your token> with the project ID from the landing page (see screenshot below), and the token from step 2:

ksnip_20221026-102515
curl --location --request PUT 'http://localhost:3000/api/v4/projects/<project id> --header 'Authorization: Bearer <your token>' --header 'Content-Type: application/json' --data-raw '{ "only_allow_merge_if_all_status_checks_passed": true }'
  1. Using the Web IDE, make any change, then commit it to a new branch and create a MR for it:
ksnip_20221026-125224
  1. You should be redirected to the MR details page. Wait for the pipeline to finish, and you should see the status checks widget with the status pending. Verify that the "merge blocked" message is shown:
ksnip_20221026-125514
  1. Use the following curl command to set the status check to failed, replacing <project id>, <merge request id>, <your token>, , and <status check id>. The status check ID should be 1, assuming you haven't created another status check before, and sha is the sha of the MR commit. Note that this is a one-way operation; you will not be able to set the status check back to pending afterwards without creating a new MR:
curl --request POST 'http://localhost:3000/api/v4/projects/<project id>/merge_requests/<merge request id>/status_check_responses' --header 'Authorization: Bearer <your token>' --data-raw '{ "id": 20, "merge_request_iid": 4, "sha": "<sha>", "external_status_check_id": <status check id>, "status": "failed" }' --header 'Content-Type: application/json'
  1. Refresh the MR details page, and verify that the "merge blocked" message is shown:
ksnip_20221026-130829

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 #369861 (closed)

Edited by Daniel Tian

Merge request reports