{{ if has "github" .Values.global.gitProviders }}
{{- $registry := include "edp-tekton.registry" . -}}
{{ if or ( .Values.pipelines.deployableResources.java.java8 ) ( .Values.pipelines.deployableResources.java.java11 ) ( .Values.pipelines.deployableResources.java.java17 )}}
{{- $raw := include "edp-tekton.resourceMapping.maven" . | fromYaml -}}
{{- $rawSonar := include "edp-tekton.resourceMapping.mavenSonar" . | fromYaml -}}
{{- range $framework, $image := $raw }}
{{- $sonarImage := pluck $framework $rawSonar | first -}}
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: github-maven-{{ $framework }}-app-review
  labels:
    app.edp.epam.com/pipelinetype: review
    {{- include "edp-tekton.labels" $ | nindent 4 }}
spec:
  description: "The Review pipeline for building {{ $framework }} application with Maven"
  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/sergk/spring-petclinic"
      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: '{{ $framework }}-maven'
      description: "Project name"
      type: string
    - name: CODEBASEBRANCH_NAME
      description: "Codebasebranch name"
      type: string
    - name: image
      default: '{{ $image }}'
      description: "maven image version"
      type: string
    - name: sonar_image
      default: '{{ $sonarImage }}'
      description: "sonar image version"
      type: string
    - name: gitfullrepositoryname
      description: "repository full name"
      type: string
    - name: gitsha
      description: "commit sha"
      type: string
    - name: CHART_DIR
      description: "Deploy templates directory for helm-lint"
      default: "deploy-templates"
    - name: CT_CONFIGS_DIR
      description: "ct-configs directory for helm-lint"
      default: "."
  tasks:

{{- include "github-review-start" $ | nindent 4 }}

{{- include "helm-docs" $ | nindent 4 }}

{{- include "get-cache" $ | nindent 4 }}

{{- include "java-maven-get-module" . | nindent 4 }}

{{- include "java-maven-review-common" . | nindent 4 }}

{{- include "save-cache" $ | nindent 4 }}

    - name: dockerfile-lint
      taskRef:
        kind: Task
        name: hadolint
      runAfter:
        - fetch-repository
      workspaces:
        - name: source
          workspace: shared-workspace
          subPath: source

{{ include "dockerbuild-verify-maven" $ | nindent 4 }}

    - name: helm-lint
      taskRef:
        kind: Task
        name: helm-lint
      runAfter:
        - fetch-repository
      params:
        - name: CHART_DIR
          value: $(params.CHART_DIR)
        - name: CT_CONFIGS_DIR
          value: $(params.CT_CONFIGS_DIR)
      workspaces:
        - name: source
          workspace: shared-workspace
          subPath: source

{{ include "github-review-vote" $ | nindent 2 }}

---
{{ end }}
{{ end }}
{{ end }}
