sonarqube_pr_check:
  stage: test
  image: sonarsource/sonar-scanner-cli:latest
  variables:
    SONAR_USER_HOME: "$CI_PROJECT_DIR/.sonar"
    GIT_DEPTH: "0"
  cache:
    key: sonarqube-$CI_PROJECT_ID
    paths:
      - .sonar/cache
  script:
    - >
      sonar-scanner
      -Dsonar.projectKey=$SONAR_PROJECT_KEY
      -Dsonar.host.url=$SONAR_HOST_URL
      -Dsonar.token=$SONAR_TOKEN
      -Dsonar.qualitygate.wait=true
      -Dsonar.pullrequest.key=$CI_MERGE_REQUEST_IID
      -Dsonar.pullrequest.branch=$CI_COMMIT_REF_NAME
      -Dsonar.pullrequest.base=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
