Skip to main content
Skip table of contents

Merge Checks (up to version 4)

Code Owners app consists of two parts:

1. Who is responsible for what part of you code? 

   => Owner rules

The members of group JavaDevs are responsible for all Java source code is defined by a Code Owner rule like:

CODE
**/*.java @@JavaDevs

Owner rules define which groups and users are active code owners in a pull request.

These active code owners are added as reviewers to the pull request.

2. How many of these Code Owners need to approve before a pull request can be merged?

   => Merge checks

Merge Checks in CODEOWNERS files are supported since version 4.0, older versions support basic Merge checks in repository settings only.

Changes in Java source code must be reviewed and approved by at least 2 members of the JavaDevs group is defined as a merge check in the CODEOWNERS file like:

CODE
Check(@@JavaDevs >= 2)

Merge checks are active and checked for a pull request if the referenced Owner group is active in this pull request.


How to combine multiple Merge checks?

If you add multiple merge checks each on its own line to the CODEOWNERS file,
all active Merge checks (aka. AND) get checked and must be fulfilled, before a pull request can be merged.

If either one Merge check or another needs to be fulfilled for a pull request to be merged,
combine the merge checks on one line with the OR syntax like:

CODE
(Check(@@JavaDevs >= 2) | Check(@@TeamLeads >= 1))

Read this as "two Java devs or one team lead need to approve" before a pull request can be merged.

All groups must be active in a OR Merge check for the check to be active in a pull request.

How to require all members of a group to approve in a Merge check?

Use * instead of a positive integer in the Merge check:

CODE
Check(@@JavaDevs >= *)

How to require approvals by Code Owners independent of groups?

Use the overall check type like:

CODE
OverallCheck(2)

Important: This check type must not be combined with other Merge Checks in the same CODEOWNERS file.

Use * instead of positive integer to require all Code Owners to approve.

Corresponds to the first option of Merge Check settings in previous versions:

How to require approvals for each active group and all mentioned individually in an Owner rule?

Use the all groups check type like:

CODE
AllGroupsCheck(1)

Important: This check type must not be combined with other Merge Checks in the same CODEOWNERS file.

Corresponds to the first option of Merge Check settings in previous versions:


If you need help converting your requirements into Merge Check rules, or if you have an uncovered use case, please let us know.


Examples

CODE
@@@Backend @Lisa @Laura
@@@Frontend @Tom @Tim @Travis @Timo

**/*.java @@Backend
**/*.js @@Frontend

# At least one member of the Backend team must approve changes in Java code.
Check(@@Backend >= 1)
# At least 2 approvals required by Frontend team for changes in JavaScript code.
Check(@@Frontend >= 2)


CODE
@@@Backend @Lisa @Laura @Louis @Lucas
**/main/*.java @@Backend

@@@BackendTests @@Backend
**/test/*.java @@BackendTests

# At least two approvals for changes in Java main code.
Check(@@Backend >= 2)
# Only one team member must approve, if pull request changes only Java tests.
Check(@@BackendTests >= 1)


CODE
@@@Seniors @Lisa @Laura
@@@Juniors @Tom @Tim @Travis @Timo

**/*.java @@Seniors @@Juniors

# At least a senior OR two juniors must approve, before pull request with changes in Java files can be merged.
(Check(@@Seniors >= 1) | Check(@@Juniors >= 2))

Invalid Examples

CODE
@@@Seniors @Lisa @Laura

**/*.java @@Seniors @Tom @Tim @Travis @Timo 

OverallCheck(2)

# No other Merge Check allowed in same CODEOWNERS file beside OverallCheck!
# Following check is illegal:
Check(@@Seniors >= 1)


CODE
@@@Backend @Lisa @Laura
@@@Frontend @Tom @Tim @Travis @Timo

**/*.java @@Backend
**/*.js @@Frontend

AllGroupsCheck(1)

# No other Merge Check allowed in same CODEOWNERS file beside AllGroupsCheck!
# Following check is illegal:
Check(@@Frontend >= 2)


Syntax

Group merge check for group:

  • CODE
    Check(GROUP_IDENTIFIER >= QUOTA)
  • with:

    • GROUP_IDENTIFIER: two @s followed by group name

    • QUOTA: positive integer or * for all group members

Combine multiple group checks:

  1. OR: Multiple group checks in parenthesis separated by |

    1. CODE
      (Check(@@Seniors >= 1) | Check(@@Juniors >= 2))

Rules

  1. Group based checks:

    1. CODE
      Check(@@GROUP_NAME >= QUOTA)
    2. Only one check per line, except OR case.

    3. For checks on different lines, all must be fulfilled (AND)

    4. Check is active, if all groups referenced in line are explicitly referenced in an active CODEOWNERS rule in pull request:

      CODE
      @@@Backend @Lisa @Laura
      @@@Frontend @Tom @Tim @Travis @Timo
      @@@FullTeam @@Backend @@Frontend
      
      dirBackend/    @@Backend
      dirFrontend/   @@Frontend
      dirShared/     @@FullTeam
      
      # *only* active on dirBackend:
      Check(@@Backend >= 1)
      # *only* active on dirFrontend:
      Check(@@Frontend >= 1)
      # *only* active  on dirShared:
      Check(@@FullTeam >= 1)
      # not active on any rule:
      (Check(@@Backend >= 2) | Check(@@Frontend >= 3))

  2. OverallCheck and AllGroupsCheck:

    1. Only allowed as single check in CODEOWNERS file.

  3. Multiple CODEOWNERS file active:

    1. Merge checks are checked for each file independently

  4. PR author does not count towards check quota, except if the PR author is the only active Code Owner.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.