Skip to content

Display correct approval rules based on target branch in Edit MR form

Issue: #199790 (closed)

What does this MR do?

Filter out the rules that are not scoped to the correct target branch. And if the user changes the target branch during editing of the MR, it will display the correct rules that are scoped to that selected branch.

Note

Implementing the easiest and boring solution, based on this conversation here > #199790 (comment 294461557) and working iteratively here 👍 So I'm using MutationObserver to listen for the changes in the target branch dropdown.

A follow-up issue to convert the target branch into a Vue component will be addressed here > #210507

Testing Case

Setup

Let's setup our rules in the project settings so we can test out the toggle rule in edit MR...

  1. Go to Settings > General > expand "Merge request approvals"
  2. Add 2 new approval rules
  3. Create a new rule named "Any Rule" and target it to any branch
  4. Create a new rule named "Master Rule" and target it to "master" branch

(For details on how to add a rule scoped to a particular branch, please see the testing case of this MR > !24344 (merged))

Here's the end result you should see:

image

Create a new random new merge request targeting the master branch.

Edit MR

  1. Click on "Edit" to edit the merge request
  2. Here's what the rules look like:

image

  1. Change the target branch from "master" --> "development"

image

  • The "master" rule is now gone (b/c it's scoped to the "master" branch NOT the "development" branch)

image

  • And if you watch it back to the "master" branch, it will display the "Master Rule" again

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Closes #199790 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports