---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name:  tektoncd-operator-run-on-pr
  annotations:
    pipelinesascode.tekton.dev/on-event: "[pull_request]"
    pipelinesascode.tekton.dev/on-target-branch: "[release-next]"
    pipelinesascode.tekton.dev/task: "[git-clone, golang-test]"
spec:
  params:
    - name: repo_url
      value: {{repo_url}}
    - name: revision
      value: {{revision}}
  pipelineSpec:
    params:
      - name: repo_url
      - name: revision
    tasks:
      - name: fetch
        taskRef:
          name: git-clone
        params:
          - name: url
            value: $(params.repo_url)
          - name: revision
            value: $(params.revision)
        workspaces:
          - name: output
            workspace: source
      - name: test
        runAfter: [fetch]
        taskRef:
          name: golang-test
        params:
          - name: package
            value: "github.com/openshift/tektoncd-operator"
        workspaces:
          - name: source
            workspace: source
  finally:
    - name: finally
      taskSpec:
        steps:
          - name: send-to-slack
            env:
              - name: SLACK_WEBHOOK_URL
                valueFrom:
                  secretKeyRef:
                    name: slack-tektoncd-operator-ci-webhook
                    key: hook_url
              - name: PIPELINERUN
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.labels['tekton.dev/pipelineRun']
              - name: GITHUB_PULL_LABEL
                value: "{{pull_request.labels}}"
              - name: LABEL_TO_CHECK
                value: "nightly-ci"
              - name: SUCCESS_URL_ICON
                value: "https://github.com/tektoncd.png"
              - name: FAILURE_URL_ICON
                value: "https://user-images.githubusercontent.com/4288561/114842214-eecf6c80-9dd8-11eb-8924-86288b1a501c.jpeg"
              - name: SUCCESS_SUBJECT
                value: "Tektoncd Operator CI ran successfull on {{pull_request.html_url}} :pipelines: :dance_cat: :yay2:"
              - name: FAILURE_SUBJECT
                value: "Tektoncd Operator CI has failed on {{pull_request.html_url}} :pipeline: :sadparrot: :failed:"
              - name: LOG_URL
                value: "{{openshift_console_pipelinerun_href}}"

            image: quay.io/chmouel/tekton-asa-code:latest
            command: ["/code/misc/send-slack-notifications.py"]

  workspaces:
  - name: source
    volumeClaimTemplate:
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
