Conditions (the if property) determine whether a rule should be applied based on various criteria. They allow you to target specific pull requests based on authors, branches, files, labels, and more.

Condition Structure

Conditions are defined in the if array of a rule:

if:
  - type: "condition_type"
    # condition parameters
  - type: "another_condition_type"
    # condition parameters

All conditions must pass for the rule to be applied. Each condition has a type and type-specific parameters.

Available Condition Types

Usage Examples

Filter by Author

Only apply a rule to PRs from specific users:

if:
  - type: "author"
    match: "username1" # Can also be an array: ["username1", "username2"]

Filter by Branch

Only apply a rule to PRs targeting a specific branch:

if:
  - type: "branch"
    base:
      match: "main"

Filter by Files Changed

Only apply a rule when specific files are modified:

if:
  - type: "files"
    modified:
      match: "src/backend/.+\\.js$"

Filter by Label

Only apply a rule to PRs with specific labels:

if:
  - type: "label"
    match: "bug" # Can also be an array: ["bug", "critical"]

Multiple Conditions

All conditions must pass for the rule to be applied:

if:
  - type: "branch"
    base:
      match: "main"
  - type: "label"
    match: "security"
  - type: "author"
    ignore: "dependabot"

This rule will only apply to PRs:

  • Targeting the main branch, AND
  • Labeled with security, AND
  • Not created by dependabot

Pattern Matching

Most conditions support pattern matching, which can be:

  • Exact match: "main"
  • Glob pattern: "feat/*"
  • Regular expression: "/^feat\/.+$/"

When using regular expressions, enclose the pattern in forward slashes (/pattern/).

Complete Example

ruleset:
  - name: "Frontend Code Review"
    when:
      - "pull_request.opened"
      - "pull_request.synchronize"
    if:
      - type: "files"
        modified:
          match: "src/frontend/.+\\.(js|ts|jsx|tsx)$"
      - type: "branch"
        base:
          match: "main"
      - type: "author"
        ignore: "dependabot"
    validate:
      - type: "size"
        files: 10
    on_failure:
      - comment:
          body: "Frontend PRs should modify no more than 10 files"

This rule only applies to PRs that:

  • Modify frontend JavaScript/TypeScript files
  • Target the main branch
  • Are not created by Dependabot