# Automatic merging of approved PRs for Zebra
#
# This file can be edited and validated using:
# https://dashboard.mergify.com/github/ZcashFoundation/repo/zebra/config-editor

queue_rules:
  - name: urgent
    # Allow to update/rebase the original pull request if possible to check its mergeability,
    # and it does not create a draft PR if not needed
    allow_inplace_checks: True
    allow_checks_interruption: False
    speculative_checks: 1
    batch_size: 8
    # Wait a short time to embark hotfixes together in a merge train
    batch_max_wait_time: "2 minutes"
    conditions:
      # Mergify automatically applies status check, approval, and conversation rules,
      # which are the same as the GitHub main branch protection rules
      # https://docs.mergify.com/conditions/#about-branch-protection
      - base=main

  - name: batched
    allow_inplace_checks: True
    allow_checks_interruption: True
    speculative_checks: 1
    batch_size: 20
    # Wait for about 10% of the time it takes Rust PRs to run CI (3h)
    batch_max_wait_time: "20 minutes"
    conditions:
      - base=main

# These rules are checked in order, the first one to be satisfied applies
pull_request_rules:
  - name: move to urgent queue when CI passes with multiple reviews
    conditions:
      # This queue handles a PR if it:
      # has multiple approving reviewers
      - "#approved-reviews-by>=2"
      # is labeled with Critical priority
      - 'label~=^P-Critical'
      # and satisfies the standard merge conditions:
      # targets main
      - base=main
      # is not in draft
      - -draft
      # does not include the do-not-merge label
      - label!=do-not-merge
    actions:
      queue:
        name: urgent
        method: squash

  - name: move to urgent queue when CI passes with 1 review
    conditions:
      # This queue handles a PR if it:
      # has at least one approving reviewer (branch protection rule)
      # does not need extra reviews
      - 'label!=extra-reviews'
      # is labeled with Critical priority
      - 'label~=^P-Critical'
      # and satisfies the standard merge conditions:
      - base=main
      - -draft
      - label!=do-not-merge
    actions:
      queue:
        name: urgent
        method: squash

  - name: move to batched queue when CI passes with multiple reviews
    conditions:
      # This queue handles a PR if it:
      # has multiple approving reviewers
      - "#approved-reviews-by>=2"
      # is labeled with any other priority (rules are checked in order)
      # and satisfies the standard merge conditions:
      - base=main
      - -draft
      - label!=do-not-merge
    actions:
      queue:
        name: batched
        method: squash

  - name: move to batched queue when CI passes with 1 review
    conditions:
      # This queue handles a PR if it:
      # has at least one approving reviewer (branch protection rule)
      # does not need extra reviews
      - 'label!=extra-reviews'
      # is labeled with any other priority (rules are checked in order)
      # and satisfies the standard merge conditions:
      - base=main
      - -draft
      - label!=do-not-merge
    actions:
      queue:
        name: batched
        method: squash
