Add merge blocked message to status checks MR widget on pending/failed
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 |
---|---|
Describe in detail what your merge request does and why. |
How to set up and validate locally
-
Enable the
only_allow_merge_if_all_status_checks_passed
feature flag. -
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:
- Go to a project,
Settings -> Merge requests
, scroll down to Status checks, and clickAdd status check
:
-
In the
Add status check
modal, fill it out with any name and a fake URL for theAPI to check
, then save it. -
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:
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 }'
- Using the Web IDE, make any change, then commit it to a new branch and create a MR for it:
- 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:
- Use the following
curl
command to set the status check tofailed
, replacing<project id>
,<merge request id>
,<your token>
, , and<status check id>
. The status check ID should be1
, 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 topending
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'
- Refresh the MR details page, and verify that the "merge blocked" message is shown:
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 #369861 (closed)