{{ if has "gitlab" .Values.global.gitProviders }}
{{ if .Values.pipelines.deployableResources.groovy }}
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: gitlab-codenarc-codenarc-lib-review
  labels:
    app.edp.epam.com/pipelinetype: review
    {{- include "edp-tekton.labels" . | nindent 4 }}
spec:
  description: "The Review pipeline for building Groovy"
  workspaces:
    - name: shared-workspace
    - name: ssh-creds
  params:
    - name: pipelineUrl
      default: https://portal-{{ .Release.Namespace }}.{{ .Values.global.dnsWildCard }}/c/main/pipelines/$(context.pipelineRun.namespace)/$(context.pipelineRun.name)
      type: string
    - name: git-source-url
      default: "https://github.com/epmd-edp/groovy-pipeline-codenarc-codenarc"
      description: git url to clone
      type: string
    - name: git-source-revision
      description: 'git revision to checkout (branch, tag, sha, ref…)'
      default: "edp"
      type: string
    - name: git-refspec
      description: Refspec to fetch before checking out revision.
      default: ""
      type: string
    - name: targetBranch
      description: Target branch of Merge Request
    - name: changeNumber
      description: Change number from Merge Request
    - name: CODEBASE_NAME
      default: 'groovy-pipeline'
      description: "Project name"
      type: string
    - name: CODEBASEBRANCH_NAME
      description: "Codebasebranch name"
      type: string
    - name: image
      default: '{{ include "edp-tekton.registry" . }}/gradle:7.6.1-jdk11'
      description: "gradle image version"
      type: string
    - name: gitfullrepositoryname
      description: "repository full name"
      type: string
  tasks:

{{- include "gitlab-review-start" . | nindent 4 }}

    - name: build
      taskRef:
        kind: Task
        name: codenarc
      runAfter:
        - init-values
      params:
        - name: BASE_IMAGE
          value: $(params.image)
        - name: EXTRA_ARGS
          value: |
            -PnexusMavenRepositoryUrl=${NEXUS_HOST_URL}/repository/edp-maven-group \
            build -x test -x compileGroovy
      workspaces:
        - name: source
          workspace: shared-workspace
          subPath: source

    - name: sonar
      taskRef:
        kind: Task
        name: sonarqube-gradle
      runAfter:
        - build
      params:
        - name: BASE_IMAGE
          value: $(params.image)
        - name: SONAR_PROJECT_KEY
          value: $(params.CODEBASE_NAME)
        - name: SONAR_PROJECT_NAME
          value: $(params.CODEBASE_NAME)
        - name: EXTRA_COMMANDS
          value: |
            -PnexusMavenRepositoryUrl=${NEXUS_HOST_URL}/repository/edp-maven-group \
            -Dsonar.projectKey=$(params.CODEBASE_NAME) \
            -Dsonar.projectName=$(params.CODEBASE_NAME) \
            -Dsonar.host.url=${SONAR_HOST_URL} \
            -Dsonar.qualitygate.wait=true \
            -Dsonar.pullrequest.key=$(params.changeNumber) \
            -Dsonar.pullrequest.branch=$(params.git-source-revision) \
            -Dsonar.pullrequest.base=$(params.targetBranch) \
            -x compileGroovy \
            sonarqube
      workspaces:
        - name: source
          workspace: shared-workspace
          subPath: source

{{ include "gitlab-review-vote" . | nindent 2 }}

{{ end }}
{{ end }}
