shared:
  - &source_code_files files~=^(?=.*((\.(go|h|cpp)|go.sum|go.mod|CMakeLists.txt|conanfile\.*))).*$
  - &no_source_code_files -files~=^(?=.*((\.(go|h|cpp)|go.sum|go.mod|CMakeLists.txt|conanfile\.*))).*$

pull_request_rules:
  - name: Add needs-dco label when DCO check failed
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,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+){1,2}$
          - base=sql_beta
      - status-success=DCO
    actions:
      label:
        remove:
          - needs-dco
        add:
          - dco-passed

  - name: Test passed for code changed-master 
    conditions:
      - or:
          - base=sql_beta
          - base=master
          - base~=^2(\.\d+){1,2}$
      - 'status-success=Build and test AMD64 Ubuntu 20.04'
      - 'status-success=Code Checker AMD64 Ubuntu 20.04'
      # - 'status-success=Code Checker MacOS 12'
      - 'status-success=Code Checker Amazonlinux 2023'
      - 'status-success=cpu-e2e'
      - 'status-success=codecov/patch'
      - 'status-success=codecov/project'
    actions:
      label:
        add:
          - ci-passed
  - name: Test passed for code changed -2.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 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 tests changed
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,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=sql_beta
          - base~=^2(\.\d+){1,2}$
      - -files~=^(?!.*\.(md)).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for non go or c++ code changed
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - 'status-success=cpu-e2e'
      - *no_source_code_files
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for go unittest code changed-master
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - 'status-success=Build and test AMD64 Ubuntu 20.04'
      - 'status-success=Code Checker AMD64 Ubuntu 20.04'
      # - 'status-success=Code Checker MacOS 12'
      - 'status-success=Code Checker Amazonlinux 2023'
      - 'status-success=UT for Go'
      - or:
          - -files~=^(?!pkg\/.*_test\.go).*$
          - -files~=^(?!internal\/.*_test\.go).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for go unittest code changed -2.2.*
    conditions:
      - base~=^2\.2\.\d+$
      - '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 mergify changed
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - -files~=^(?!\.github\/mergify\.yml).*$
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for title skip e2e
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - title~=\[skip e2e\]
      - label=kind/enhancement
      - *no_source_code_files
    actions:
      label:
        add:
          - ci-passed

  - name: Blocking PR if missing a related issue or doesn't have kind/enhancement label
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - and:
          - -body~=\#[0-9]{1,6}(\s+|$)
          - -body~=https://github.com/milvus-io/milvus/issues/[0-9]{1,6}(\s+|$)
      - or:
        - and:
          - label=kind/enhancement
          - or:
            - label=size/L
            - label=size/XL
            - label=size/XXL
        - label=kind/bug
        - label=kind/feature
          
      - -label=kind/doc
      - -label=kind/test
      - -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:
      - and:
          - or:
              - base=master
              - base=sql_beta
              - base~=^2(\.\d+){1,2}$
          - or:
              - body~=\#[0-9]{1,6}(\s+|$)
              - body~=https://github.com/milvus-io/milvus/issues/[0-9]{1,6}(\s+|$)
    actions:
      label:
        remove:
          - do-not-merge/missing-related-issue

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

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

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

  - name: Test passed for skip e2e-master
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - 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 Amazonlinux 2023'
      - *source_code_files
    actions:
      label:
        add:
          - ci-passed

  - name: Test passed for skip e2e - 2.2.*
    conditions:
      - base~=^2\.2\.\d+$
      - 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'
      - *source_code_files
    actions:
      label:
        add:
          - ci-passed

  - name: Assign the 'lgtm' and 'approved' labels following the successful testing of the 'Update Knowhere Commit'
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - 'title~=Update Knowhere Commit'
      - label=ci-passed
    actions:
      label:
        add:
          - lgtm
          - approved

  - name: Remove ci-passed label when status for code checker or ut is not success-master
    conditions:
      - label!=manual-pass
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - *source_code_files
      - 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 Amazonlinux 2023'
    actions:
      label:
        remove:
          - ci-passed

  - name: Remove ci-passed label when status for code checker or ut  is not success-2.2.*
    conditions:
      - label!=manual-pass
      - base~=^2\.2\.\d+$
      - *source_code_files
      - 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 jenkins job is not success
    conditions:
      - label!=manual-pass
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,2}$
      - -title~=\[skip e2e\]
      - files~=^(?!(.*_test\.go|.*\.md)).*$
      - 'status-success!=cpu-e2e'
    actions:
      label:
        remove:
          - ci-passed

  - name: Add comment when jenkins job failed
    conditions:
      - or:
          - base=master
          - base=sql_beta
          - base~=^2(\.\d+){1,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:
      - or:
          - base=master
          - base~=^2(\.\d+){1,2}$
          - base=sql_beta
      - 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.2.*
    conditions:
      - base~=^2\.2\.\d+$
      - 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 'do-not-merge/invalid-pr-format' label for invalid PR titles
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - or:
        - '-title~=^(feat:|enhance:|fix:|test:|doc:|auto:|\[automated\])'
        - body=^$
    actions:
      label:
        add:
          - do-not-merge/invalid-pr-format
      comment:
        message: |
          @{{author}} 

          **Invalid PR Title Format Detected**

          Your PR submission does not adhere to our required standards. To ensure clarity and consistency, please meet the following criteria:

          1. **Title Format:** The PR title must begin with one of these prefixes:
            - `feat:` for introducing a new feature.
            - `fix:` for bug fixes.
            - `enhance:` for improvements to existing functionality.
            - `test`: for add tests to existing functionality.
            - `doc`: for modifying documentation.
            - `auto`: for the pull request from bot.

          2. **Description Requirement:** The PR must include a non-empty description, detailing the changes and their impact.

          **Required Title Structure:**

          ```
          [Type]: [Description of the PR]
          ```

          Where `Type` is one of `feat`, `fix`, `enhance`, `test` or `doc`. 

          **Example:**
          ```
          enhance: improve search performance significantly 
          ```

          Please review and update your PR to comply with these guidelines.

  - name: Remove 'do-not-merge/invalid-pr-format' label for valid PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^(feat:|enhance:|fix:|test:|doc:|auto:|\[automated\])'
      - '-body=^$'
      - 'label=do-not-merge/invalid-pr-format'
    actions:
      label:
        remove:
          - do-not-merge/invalid-pr-format

  - name: Label bug fix PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^fix:'
    actions:
      label:
        add:
          - kind/bug

  - name: Label feature PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^feat:'
    actions:
      label:
        add:
          - kind/feature

  - name: Label enhancement PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^enhance:'
    actions:
      label:
        add:
          - kind/enhancement

  - name: Label test PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^test:'
    actions:
      label:
        add:
          - kind/test

  - name: Label doc PRs
    conditions:
      - or:
        - base=master
        - base~=^2(\.\d+){1,2}$
      - 'title~=^doc:'
    actions:
      label:
        add:
          - kind/doc

        
