---
apiVersion: tekton.dev/v1
kind: Task
metadata:
  name: github-set-status
spec:
  params:
  - name: SHA
  - name: STATE
  - name: REPO
  volumes:
  - name: githubtoken
    secret:
      secretName: githubtoken
  steps:
    - name: set-status
      # curlimages/curl:8.6.0
      image: curlimages/curl@sha256:f2237028bed58de91f62aea74260bb2a299cf12fbcabc23cfaf125fef276c884
      env:
      - name: SHA
        value: $(params.SHA)
      - name: STATE
        value: $(params.STATE)
      - name: REPO
        value: $(params.REPO)
      volumeMounts:
        - name: githubtoken
          mountPath: /etc/github-set-status
      script: |
        #!/bin/sh
        curl -L \
             -X POST \
             -H "Accept: application/vnd.github+json" \
             -H "Authorization: Bearer $(cat /etc/github-set-status/token)" \
             -H "Content-Type: application/json" \
             -H "X-GitHub-Api-Version: 2022-11-28" \
             "https://api.github.com/repos/${REPO}/statuses/${SHA}" \
             -d '{
                   "state":"'${STATE}'",
                   "target_url":"http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/#/namespaces/default/pipelineruns/",
                   "description":"Tekton build is in state: '${STATE}'",
                   "context":"Tekton"
                 }'