Files
cicd/tasks/gitea-set-status.yaml

77 lines
2.4 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: gitea-set-status
namespace: goghvideo-cicd-pipeline
spec:
description: |-
This task will set the status of the CI job to the specified value along with a link to the specified target URL where developers can follow the progress of the CI job.
The `gitea-set-status` task allows external services to mark Gitea commits with an `error`, `failure`, `pending`, or `success` state, which is then reflected in pull requests involving those commits. Statuses include as well a `description` and a `target_url`, to give the user informations about the CI statuses or a direct link to the full log.
params:
- name: githost
type: string
- name: quayhost
type: string
- name: repofullname
type: string
- name: revision
type: string
- name: statusurl
type: string
- name: description
type: string
- name: context
type: string
default: continuous-integration/tekton
- name: state
type: string
steps:
- image: $(params.quayhost)/goghvideo/python:3-alpine
name: set-status
script: |
#!/usr/bin/env python
"""This script will set the CI status on a Gitea commit"""
import json
import sys
import http.client
gitea_token = open("$(workspaces.gitauth.path)/password", "r").read()
status_url = "/api/v1/repos/$(params.repofullname)/statuses/$(params.revision)"
data = {
"state": "$(params.state)",
"target_url": "$(params.statusurl)",
"description": "$(params.description)",
"context": "$(params.context)"
}
print("Sending this data to Gitea: ")
print(data)
authHeader = "token " + gitea_token
conn = http.client.HTTPSConnection("$(params.githost)")
conn.request(
"POST",
status_url,
body=json.dumps(data),
headers={
"User-Agent": "TektonCD, the peaceful cat",
"Authorization": authHeader,
"Accept": "application/json",
"Content-Type": "application/json",
})
resp = conn.getresponse()
if not str(resp.status).startswith("2"):
print("Error: %d" % (resp.status))
print(resp.read())
sys.exit(1)
else:
print("Gitea status has been set")
workspaces:
- name: gitauth