mirror of
https://github.com/tektoncd/catalog.git
synced 2024-11-25 06:17:50 +00:00
61bd4641ab
(cherry picked from commit 5e71cc4e71
)
101 lines
2.8 KiB
YAML
101 lines
2.8 KiB
YAML
---
|
|
apiVersion: tekton.dev/v1beta1
|
|
kind: Task
|
|
metadata:
|
|
name: github-set-status
|
|
description: |
|
|
This task will set the CI as running and add a link to the openshift console
|
|
viewer url.
|
|
spec:
|
|
params:
|
|
- name: GITHUB_HOST_URL
|
|
description: |
|
|
The GitHub host, adjust this if you run a GitHub enteprise.
|
|
default: "api.github.com"
|
|
type: string
|
|
|
|
- name: API_PATH_PREFIX
|
|
description: |
|
|
The API path prefix, GitHub Enterprise has a prefix e.g. /api/v3
|
|
default: ""
|
|
type: string
|
|
|
|
- name: REPO_FULL_NAME
|
|
description: |
|
|
The GitHub repository full name, i.e: tektoncd/catalog
|
|
type: string
|
|
|
|
- name: SHA
|
|
description: |
|
|
Commit SHA to set the status for.
|
|
type: string
|
|
|
|
- name: TARGET_URL
|
|
description: |
|
|
The target URL to associate with this status. This URL will be linked
|
|
from the GitHub UI to allow users to easily see the source of the
|
|
status.
|
|
type: string
|
|
|
|
- name: DESCRIPTION
|
|
description: |
|
|
A short description of the status.
|
|
type: string
|
|
|
|
- name: CONTEXT
|
|
description: |
|
|
The GitHub context, A string label to differentiate this status from
|
|
the status of other systems. ie: "continuous-integration/tekton"
|
|
default: "continuous-integration/tekton"
|
|
type: string
|
|
|
|
- name: STATE
|
|
description: |
|
|
The state of the status. Can be one of the following `error`,
|
|
`failure`, `pending`, or `success`.
|
|
type: string
|
|
steps:
|
|
- name: set-status
|
|
env:
|
|
- name: GITHUBTOKEN
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: github
|
|
key: token
|
|
|
|
image: registry.access.redhat.com/ubi8/ubi:latest
|
|
script: |
|
|
#!/usr/libexec/platform-python
|
|
import json
|
|
import os
|
|
import http.client
|
|
|
|
status_url = "$(params.API_PATH_PREFIX)" + "/repos/$(params.REPO_FULL_NAME)/" + \
|
|
"statuses/$(params.SHA)"
|
|
|
|
data = {
|
|
"state": "$(params.STATE)",
|
|
"target_url": "$(params.TARGET_URL)",
|
|
"description": "$(params.DESCRIPTION)",
|
|
"context": "$(params.CONTEXT)"
|
|
}
|
|
print("Sending this data to GitHub: ")
|
|
print(data)
|
|
|
|
conn = http.client.HTTPSConnection("$(params.GITHUB_HOST_URL)")
|
|
r = conn.request(
|
|
"POST",
|
|
status_url,
|
|
body=json.dumps(data),
|
|
headers={
|
|
"User-Agent": "TektonCD, the peaceful cat",
|
|
"Authorization": "Bearer " + os.environ["GITHUBTOKEN"],
|
|
})
|
|
resp = conn.getresponse()
|
|
if not str(resp.status).startswith("2"):
|
|
print("Error: %d" % (resp.status))
|
|
print(resp.read())
|
|
else:
|
|
print("GitHub status '$(params.STATE)' has been set on "
|
|
"$(params.REPO_FULL_NAME)#$(params.SHA) ")
|