{{ if has "gitlab" .Values.global.gitProviders }}
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
  name: gitlab-build-template
  labels:
    {{- include "edp-tekton.labels" . | nindent 4 }}
spec:
  params:
    - name: gitrevision
    - name: gitrepositoryurl
    - name: gitrepositoryname
    - name: gitfullrepositoryname
    - name: codebase
      description: Codebase name used in pipeline
    - name: codebasebranch
      description: Codebasebranch name used in pipeline
    - name: ticketNamePattern
      description: Ticket name pattern
    - name: commitMessagePattern
      description: Commit message pattern to run commit-validate task
    - name: commitMessage
      description: Commit message
    - name: changeNumber
      description: Change number from Merge Request
    - name: jiraIssueMetadataPayload
      description: Jira issue payload
    - name: jiraServer
      description: Jira server name
    - name: pipelineName
      description: Pipeline to trigger. Populated by edp interceptor from codebasebranch spec
  resourcetemplates:
    - apiVersion: tekton.dev/v1
      kind: PipelineRun
      metadata:
        generateName: build-$(tt.params.codebasebranch)-
        labels:
          # used by UI to sort pipelines for codebasebranches
          app.edp.epam.com/codebasebranch: $(tt.params.codebasebranch)
          app.edp.epam.com/codebase: $(tt.params.codebase)
          app.edp.epam.com/pipelinetype: build
        annotations:
          argocd.argoproj.io/compare-options: IgnoreExtraneous
      spec:
        taskRunTemplate:
          serviceAccountName: tekton
          {{ if .Values.pipelines.podTemplate }}
          podTemplate: {{ .Values.pipelines.podTemplate | toYaml | nindent 12 }}
          {{ end }}
        pipelineRef:
          name: $(tt.params.pipelineName)
        params:
          - name: git-source-url
            value: $(tt.params.gitrepositoryurl)
          - name: git-source-revision
            value: $(tt.params.gitrevision)
          - name: CODEBASE_NAME
            value: $(tt.params.codebase)
          - name: CODEBASEBRANCH_NAME
            value: $(tt.params.codebasebranch)
          - name: changeNumber
            value: $(tt.params.changeNumber)
          - name: gitfullrepositoryname
            value: $(tt.params.gitfullrepositoryname)
          - name: TICKET_NAME_PATTERN
            value: $(tt.params.ticketNamePattern)
          - name: COMMIT_MESSAGE_PATTERN
            value: $(tt.params.commitMessagePattern)
          - name: COMMIT_MESSAGE
            value: $(tt.params.commitMessage)
          - name: JIRA_ISSUE_METADATA_PAYLOAD
            value: $(tt.params.jiraIssueMetadataPayload)
          - name: JIRA_SERVER
            value: $(tt.params.jiraServer)
        workspaces:
          - name: shared-workspace
            volumeClaimTemplate:
              spec:
                accessModes:
                  - ReadWriteOnce
                resources:
                  requests:
                    storage: {{ .Values.tekton.workspaceSize }}
            subPath: codebase
          - name: ssh-creds
            secret:
              secretName: ci-gitlab
{{ end }}
