Fix "code_owner_approval_required" override when the param is not set

What does this MR do and why?

Contributes to #422092 (closed)

Problem

Grape API field with default: false sets a value for the argument even if it's missing in the request. As a result, requests that don't specify this argument will unintentionally change it to the default value.

Solution

  • Remove default: false to prevent an unintentional override
  • Add tests to cover this case

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Enable code owner approval for protected branch
curl --request PATCH "http://gdk.test:3000/api/v4/projects/2/protected_branches/master" -H 'PRIVATE-TOKEN: <GITLAB_TOKEN>'  -H 'Content-Type: application/json' --data '{"code_owner_approval_required": true}'
  1. Verify that it was enabled:
{"id":2,"name":"master", ... ,"code_owner_approval_required":true}
  1. Send another PATCH request that doesn't change code_owner_approval_required:
curl --request PATCH "http://gdk.test:3000/api/v4/projects/2/protected_branches/master" -H 'PRIVATE-TOKEN: <GITLAB_TOKEN>'  -H 'Content-Type: application/json' --data '{}'
  1. code_owner_approval_required should be unaffected:
{"id":2,"name":"master", ... ,"code_owner_approval_required":true}

Related to #422092 (closed)

Edited by Vasilii Iakliushin

Merge request reports

Loading