queue_rules:
  - name: default
    conditions: []

pull_request_rules:
  - name: Automatic merge on approval
    conditions:
      - and:
        - "#review-threads-unresolved=0"
        - "#approved-reviews-by>=2"
        - "#changes-requested-reviews-by=0"
        - "label!=do-not-merge"
        - "label!=mergify-ignore"
        - or:
          - and:
            - "label!=SR-Risk"
            - "label!=C-Protocol-Critical"
          - and:
            - "label=SR-Risk"
            - "approved-reviews-by=maurelian"
          - and:
            - "label=C-Protocol-Critical"
            - or:
              - "approved-reviews-by=tynes"
              - "approved-reviews-by=smartcontracts"
    actions:
      queue:
        name: default
        method: squash
  - name: Add merge train label
    conditions:
      - "queue-position >= 0"
    actions:
      comment:
          message: |
            This PR has been added to the merge queue, and will be merged soon.
      label:
        add:
          - on-merge-train
  - name: Remove merge train label
    conditions:
      - "queue-position = -1"
    actions:
      label:
        remove:
          - on-merge-train
  - name: Handle security critical PRs
    conditions:
      - "label=SR-Risk"
    actions:
      request_reviews:
        users:
          - "maurelian"
      comment:
        message: |
          Hey there @{{author}}! You flagged this PR as security critical. To make review easier, please add a comment describing

          1. The risks present in this PR.
          2. The mitigations you have added to try and reduce those risks.
  - name: Request protocol critical reviewers
    conditions:
      - label=C-Protocol-Critical
    actions:
      request_reviews:
        users:
          - tynes
          - smartcontracts
        random_count: 1
  - name: Ask to resolve conflict
    conditions:
      - conflict
    actions:
      comment:
        message: Hey @{{author}}! This PR has merge conflicts. Please fix them before continuing review.
      label:
        add:
          - conflict
  - name: Remove conflicts label when conflicts gone
    conditions:
      - -conflict
    actions:
      label:
        remove:
          - conflict
  - name: Notify author when added to merge queue
    conditions:
      - "check-pending=Queue: Embarked in merge train"
    actions:
      comment:
        message: |
          This PR is next in line to be merged, and will be merged as soon as checks pass.
  - name: Notify author when merge queue failed
    conditions:
      - "check-failure=Queue: Embarked in merge train"
    actions:
      comment:
        message: |
          Merge failed. Please see automated check logs for more details.
  - name: Nag changesets
    conditions:
      - and:
        - 'files~=\.((?<!\.spec\.)ts|go|js|mod|sum)$'
        - '-files~=^\.changeset/(.*)\.md'
    actions:
      comment:
        message: |
          This PR changes implementation code, but doesn't include a changeset. Did you forget to add one?
