include:
  - project: 'redhat/centos-stream/ci-cd/osci-pipelines'
    file: 'rog/gitlabci-rog-cs.yaml'
    ref: 'main'
    rules:
      - if: '($CI_MERGE_REQUEST_PROJECT_PATH =~ /^redhat.centos-stream/ || $CI_PROJECT_PATH =~ /^redhat.centos-stream/) &&
            (
              (
                (
                  $CI_PIPELINE_SOURCE == "merge_request_event" &&
                  $CI_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID
                ) ||
                $CI_PIPELINE_SOURCE == "push"
              ) &&
              (
                $CI_PROJECT_NAME =~ /^(libkcapi|osci-internal-test-package|some-other-package)$/ ||
                ($CI_PROJECT_NAME =~ /^(frr|gnupg2|kernel|libassuan|libgcrypt|libgpg-error|libksba|libxcrypt|meson|wireshark|npth|opensc|pcsc-lite|pcsc-lite-ccid|pinentry|rust-rpm-sequoia)$/ && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "c10s" || $CI_COMMIT_BRANCH == "c10s"))
              )
            )'
  - project: 'redhat/centos-stream/ci-cd/osci-pipelines'
    file: 'rog/gitlabci-zstream-prototype.yaml'
    ref: 'main'
    rules:
      - if: '($CI_MERGE_REQUEST_PROJECT_PATH =~ /^redhat.rhel/ || $CI_PROJECT_PATH =~ /^redhat.rhel/) &&
            (
              (
                (
                  $CI_PIPELINE_SOURCE == "merge_request_event" &&
                  $CI_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID
                ) ||
                $CI_PIPELINE_SOURCE == "push"
              ) &&
              (
                $CI_PROJECT_NAME =~ /^(osci-internal-test-package|some-other-package)$/
              )
            )'

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID'
      variables:
        PIPELINE_TYPE: 'internal'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_ID != $CI_MERGE_REQUEST_PROJECT_ID'
      variables:
        PIPELINE_TYPE: 'external'
    - if: '$CI_PIPELINE_SOURCE == "push"'

.exclude_rog_components: &exclude_rog_components
  - if: '$CI_PROJECT_NAME =~ /^libkcapi$/ && ($CI_MERGE_REQUEST_PROJECT_PATH =~ /^redhat.centos-stream/ || $CI_PROJECT_PATH =~ /^redhat.centos-stream/)'
    when: never
  - if: '$CI_PROJECT_NAME =~ /^(osci-internal-test-package|some-other-package)$/'
    when: never
  - if: '$CI_PROJECT_NAME =~ /^(frr|gnupg2|kernel|libassuan|libgcrypt|libgpg-error|libksba|libxcrypt|meson|wireshark|npth|opensc|pcsc-lite|pcsc-lite-ccid|pinentry|rust-rpm-sequoia)$/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "c10s"'
    when: never

check-access:
  image: alpine:latest
  script:
    - |
      >&2 cat << EOF
      The user that initiated this pipeline does not have permissions to execute
      code within the Red Hat intranet. Please ask the package maintainer or
      another Red Hat employee to trigger the pipeline for you by clicking on the
      "Run pipeline" button on the "Pipelines" tab of the merge request.
      EOF
      exit 1
  rules:
    - *exclude_rog_components
    - if: '$PIPELINE_TYPE == "external"'

check-tickets:
  image: registry.gitlab.com/redhat/centos-stream/ci-cd/dist-git-gating-tests/check_tickets:649
  tags:
    - redhat
    - bureaucrabot
  script:
    - |
      echo "Checking commits for approved ticket references"
      exit_code=0
      /usr/local/bin/check_tickets || exit_code=$?
      if [ $exit_code -eq 0 ]; then
         echo -e "\e[0;102mThis change is approved for merging\e[0m"
      elif [ $exit_code -eq 77 ]; then
         echo -e "\e[0;103mThis change is being allowed without approval during the active development phase\e[0m"
      else
         echo -e "\e[41mThis change does not have the requisite ticket approvals. See above for details\e[0m"
      fi
    - exit $exit_code
  allow_failure:
    exit_codes:
      - 77
  artifacts:
    paths:
      - "debug.log"
    when: always
    expire_in: 1 week
  rules:
    - *exclude_rog_components
    - if: '$PIPELINE_TYPE == "internal"'

