pull_request_rules:
  - name: Add needs-dco label when DCO check failed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -status-success=DCO
    actions:
      label:
        remove:
          - dco-passed
        add:
          - needs-dco
      comment:
        message: |
          @{{author}} Thanks for your contribution. Please submit with DCO, see the contributing guide https://github.com/milvus-io/milvus/blob/master/CONTRIBUTING.md#developer-certificate-of-origin-dco.

  - name: Add dco-passed label when DCO check passed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - status-success=DCO
    actions:
      label:
        remove:
          - needs-dco
        add:
          - dco-passed

  - name: Test passed for code changed-master
    conditions:
      - base=master
      - "status-success=Code Checker AMD64 Ubuntu 20.04"
      - "status-success=Build and test AMD64 Ubuntu 20.04"
      - "status-success=Code Checker MacOS 12"
      - "status-success=Code Checker CentOS 7"
      - "status-success=cpu-e2e"
      - "status-success=codecov/patch"
      - "status-success=codecov/project"
    actions:
      label:
        add:
          - ci-passed
  - name: Test passed for code changed -2.*.*
    conditions:
      - base~=^2(\.\d+){2}$
      - "status-success=Code Checker AMD64 Ubuntu 18.04"
      - "status-success=Build and test AMD64 Ubuntu 18.04"
      - "status-success=Code Checker MacOS 11"
      - "status-success=Code Checker CentOS 7"
      - "status-success=cpu-e2e"
      - "status-success=codecov/patch"
      - "status-success=codecov/project"
    actions:
      label:
        add:
          - ci-passed
  - name: Test passed for tests changed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -files~=^(?!tests\/python_client).+
      - "status-success=cpu-e2e"
    actions:
      label:
        add:
          - ci-passed
  
  - name: Test passed for docs changed only
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -files~=^(?!.*\.(md)).*$ 
    actions:
      label:
        add:
          - ci-passed


  - name: Test passed for non go or c++ code changed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
      - "status-success=cpu-e2e"
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for go unittest code changed-master
    conditions:
      - base=master
      - "status-success=Code Checker AMD64 Ubuntu 20.04"
      - "status-success=Build and test AMD64 Ubuntu 20.04"
      - "status-success=Code Checker MacOS 12"
      - "status-success=Code Checker CentOS 7"
      - -files~=^(?!internal\/.*_test\.go).*$
    actions:
      label:
        add:
          - ci-passed
  - name: Test passed for go unittest code changed -2.*.*
    conditions:
      - base~=^2(\.\d+){2}$
      - "status-success=Code Checker AMD64 Ubuntu 20.04"
      - "status-success=Build and test AMD64 Ubuntu 20.04"
      - "status-success=Code Checker MacOS 11"
      - "status-success=Code Checker CentOS 7"
      - -files~=^(?!internal\/.*_test\.go).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for mergify changed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -files~=^(?!\.github\/mergify\.yml).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for title skip e2e
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - title~=\[skip e2e\]
      - label=kind/improvement
      - -files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
    actions:
      label:
        add:
          - ci-passed


  - name: Blocking PR if missing a related issue or PR doesn't have kind/improvement label
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - and:
        - -body~=\#[0-9]{1,6}(\s+|$)
        - -body~=https://github.com/milvus-io/milvus/issues/[0-9]{1,6}(\s+|$)
      - -label=kind/improvement
      - -title~=\[automated\]
    actions:
      label:
        add:
          - do-not-merge/missing-related-issue
      comment:
        message: |
          @{{author}} Please associate the related issue to the body of your Pull Request.  (eg. “issue: #<xyz>”)


  - name: Dismiss block label if related issue be added into PR
    conditions:
      - or:
        - and:
          - or:
            - base=master
            - base~=^2(\.\d+){2}$
          - or:
            - body~=\#[0-9]{1,6}(\s+|$)
            - body~=https://github.com/milvus-io/milvus/issues/[0-9]{1,6}(\s+|$)
        - and:
          - base=master
          - label=kind/improvement
    actions:
      label:
        remove:
          - do-not-merge/missing-related-issue

  - name: Dismiss block label if automated create PR
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - title~=\[automated\]
    actions:
      label:
        remove:
          - do-not-merge/missing-related-issue

  - name: Test passed for skip e2e-master
    conditions:
      - base=master
      - title~=\[skip e2e\]
      - "status-success=Code Checker AMD64 Ubuntu 20.04"
      - "status-success=Build and test AMD64 Ubuntu 20.04"
      - "status-success=Code Checker MacOS 12"
      - "status-success=Code Checker CentOS 7"
      - files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for skip e2e - 2.*.*
    conditions:
      - base~=^2(\.\d+){2}$
      - title~=\[skip e2e\]
      - "status-success=Code Checker AMD64 Ubuntu 18.04"
      - "status-success=Build and test AMD64 Ubuntu 18.04"
      - "status-success=Code Checker MacOS 11"
      - "status-success=Code Checker CentOS 7"
      - files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Remove ci-passed label when status for code checker or ut  is not success-master
    conditions:
      - label!=manual-pass
      - base=master
      - files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
      - or:
        - "status-success!=Code Checker AMD64 Ubuntu 20.04"
        - "status-success!=Build and test AMD64 Ubuntu 20.04" 
        - "status-success!=Code Checker MacOS 12"    
        - "status-success!=Code Checker CentOS 7"
    actions:
      label:
        remove:
          - ci-passed
  - name: Remove ci-passed label when status for code checker or ut  is not success-2.*.*
    conditions:
      - label!=manual-pass
      - base~=^2(\.\d+){2}$
      - files~=^(?=.*((\.(go|h|cpp)|CMakeLists.txt))).*$
      - or:
        - "status-success!=Code Checker AMD64 Ubuntu 18.04"
        - "status-success!=Build and test AMD64 Ubuntu 18.04" 
        - "status-success!=Code Checker MacOS 11"    
        - "status-success!=Code Checker CentOS 7"
    actions:
      label:
        remove:
          - ci-passed
  - name: Remove ci-passed label when  status for jenkins job is not success
    conditions:
      - label!=manual-pass
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - -title~=\[skip e2e\]
      - files~=^(?!(internal\/.*_test\.go|.*\.md)).*$
      - "status-success!=cpu-e2e"        
    actions:
      label:
        remove:
          - ci-passed


  - name: Add comment when jenkins job failed
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - "check-failure=cpu-e2e"        
    actions:
      comment:
        message: |
          @{{author}} E2e jenkins job failed, comment `/run-cpu-e2e` can trigger the job again.

  - name: Add comment when code checker or ut failed -master
    conditions:
      - base=master
      - or:
        - "check-failure=Code Checker AMD64 Ubuntu 20.04"
        - "check-failure=Build and test AMD64 Ubuntu 20.04"       
    actions:
      comment:
        message: |
          @{{author}} ut workflow job failed, comment `rerun ut` can trigger the job again.

  - name: Add comment when code checker or ut failed -2.*.*
    conditions:
      - base~=^2(\.\d+){2}$
      - or:
        - "check-failure=Code Checker AMD64 Ubuntu 18.04"
        - "check-failure=Build and test AMD64 Ubuntu 18.04"       
    actions:
      comment:
        message: |
          @{{author}} ut workflow job failed, comment `rerun ut` can trigger the job again.


  - name: Add `needs-rebase` label when more than one commit in pr
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - "#commits>1"
    actions:
      comment:
        message: |
          @{{author}}, please be sure the pr should only have one commit, check https://github.com/milvus-io/milvus/blob/master/CODE_REVIEW.md for more details.
      label:
        add:
          - needs-rebase

  - name: Remove `needs-rebase` label when only one commit in pr
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){2}$
      - "#commits=1"
    actions:
      label:
        remove:
          - needs-rebase