Updated on 2025-03-27 GMT+08:00

Configuring Repository-Level Merge Request Rules

Constraints

To configure merge request rules for a repository, you need to have the necessary permissions. For details, see Configuring Repo-Level Permissions.

Configuring Merge Request Rules

You can select Inherit from project. The settings in the project are automatically inherited and cannot be changed.

You can also access the repo homepage of the code to be configured and choose Settings > Policy Settings > Merge Requests.

For details, see 1 to 3. If your merge mechanism is Approval and you want to set the merge policy for a specified branch or all branches in the repository, refer to this section.

Configuring Branch Policy

Go to the target repository homepage, choose Settings > Policy Settings > Merge Requests. In the Branch Policies area, click Create Branch Policy, and set parameters by referring to the following table.

Table 1 Parameters for creating a branch policy

Parameter

Description

Branch

Mandatory. Select a branch from the drop-down list. You can select all branches.

Reviewers Required

Mandatory. The default value is 0, indicating that the review gate can be passed without being reviewed by the reviewer.

Approvals Required

Mandatory. The default value is 0, indicating that the approval gate can be passed without being approved by the approver.

Reset approval gate

Optional. This option is selected by default, indicating that MR approval gate is reset when code is re-pushed to the source branch of the MR.

Reset review gate

Optional. This option is selected by default, indicating that the MR review gate is reset when code is re-pushed to the source branch of the MR.

Add approvers/reviewers only from the following ones

Optional. If this option is selected, you can configure the list of New Approvers and New Reviewers. If you want to add additional members, you can only add members from the lists.

Enable pipeline gate

Optional. If this option is selected, before the merge, you need to pass all pipeline gates. This rule integrates the CI into the code development process.

Mergers

Optional. The list of mandatory mergers can be configured. When a merge request is created, the list is automatically synchronized to the merge request.

Approvers

Optional. The list of mandatory approvers can be configured. When a merge request is created, the list is automatically synchronized to the merge request.

Reviewer

Optional. The list of mandatory reviewers can be configured. When a merge request is created, the list is automatically synchronized to the merge request.

FAQs About Setting Branch Policies

  1. The following is an example of the branch policy priority:
    • If a branch has both policies A and B in a repository, the latest created branch policy is used by default.
    • There are policies A and B in the repository. Branch A and branch B are configured for policy A, and branch A is also configured for policy B. When a merge request whose target branch is Branch A is committed, the policy B is used by default.
  2. If no branch policy is set in the approval mechanism, the default branch policy is used when a merge request is committed. The branch policy can be edited and viewed but cannot be deleted. The policy configuration is as follows:
    • Branches: *. By default, all branches are used and cannot be modified.
    • Reviewers Required: The default value is 0. If the value is not 0, the number of reviewers in the merge request must reach the minimum number of reviewers. Otherwise, the merge request cannot be merged.
    • Approvals Required: The default value is 0. If the value is not 0, the number of approvers in the merge request must reach the minimum number of approvers. Otherwise, the merge request cannot be merged.
    • Reset approval gate: This option is selected by default.
    • Reset review gate: This option is selected by default.
    • Add approvers/reviewers only from the following ones: This option is not selected by default.
    • Enable pipeline gate: This option is not selected by default.
    • Mergers: This parameter is left blank by default.
    • Approvers: This parameter is left blank by default. If it is not empty, the merge request can pass the approval gate only after being approved by at least one person.
    • Reviewer: This parameter is left blank by default. If the value is not empty, the merge request can pass the review gate only after being reviewed by at least one person.