Add task that runs on PR from onedev.

This commit is contained in:
James Pace 2023-01-12 20:38:56 -05:00
parent 7947a82b46
commit d521abeb57
3 changed files with 69 additions and 8 deletions

View File

@ -11,6 +11,9 @@ spec:
description: Shared data.
- name: git-credentials
description: tekton git credentials
params:
- name: pr-id
description: ID number of the current PR.
tasks:
- name: fetch-repo
workspaces:
@ -46,11 +49,11 @@ spec:
value: onedev-api-key
- name: feedback-url
value: https://git.jpace121.net/
- name: project-id
value: 9
- name: pr-id
value: $(params.pr-id)
- name: run-name
value: $(context.pipelineRun.name)
- name: status
value: $(tasks.status)
taskRef:
name: j7s-onedev-file-bug
name: j7s-onedev-pr-review

View File

@ -0,0 +1,58 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: j7s-onedev-pr-review
spec:
params:
- name: tekton-login-secret-name
- name: feedback-url
- name: pr-id
- name: run-name
- name: status
steps:
- image: 192.168.1.128:8443/curl:latest
script: |
#!/usr/bin/env bash
set -e
# Approve or request changes.
echo '{"userId" : 1, "requestId" : 1, "status" : "PENDING",
"statusDate" : ""}' > request.json
cat request.json | jq ".userId = $TEKTON_USER_ID" | jq . > request1.json
cat request1.json | jq ".requestId = $(params.pr-id)" | jq . > request2.json
cat request2.json | jq ".statusDate = \"`date +"%Y-%m-%dT%H:%M:%S%:z"`\"" | jq . > request3.json
case "$(params.status)" in
"Succeeded" | "Completed")
echo "Build was successful!"
cat request3.json | jq ".status = \"APPROVED\" " | jq . > request4.json
;;
"Failed" | "None")
cat request3.json | jq ".status = \"REQUESTED_FOR_CHANGES\" " | jq . > request4.json
;;
esac
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@request4.json \
$(params.feedback-url)/~api/pull-request-reviews
# Make a comment on the PR.
echo '{"userId" : 1, "requestId" : 1, "content" : "",
"date" : ""}' > comment.json
cat comment.json | jq ".userId = $TEKTON_USER_ID" | jq . > comment1.json
cat comment1.json | jq ".requestId = $(params.pr-id)" | jq . > comment2.json
cat comment2.json | jq ".date = \"`date +"%Y-%m-%dT%H:%M:%S%:z"`\"" | jq . > comment3.json
cat comment3.json | jq ".content = \"Tekton run: $(params.run-name).\"" | jq . > comment4.json
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@comment4.json \
$(params.feedback-url)/~api/pull-request-comments
env:
- name: TEKTON_API_KEY
valueFrom:
secretKeyRef:
name: $(params.tekton-login-secret-name)
key: accesstoken
- name: TEKTON_USER_ID
valueFrom:
secretKeyRef:
name: $(params.tekton-login-secret-name)
key: userid

View File

@ -21,8 +21,8 @@ metadata:
name: test-pipeline-binding
spec:
params:
- name: empty
value: empty
- name: pr-id
value: $(body.pr-id)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
@ -30,7 +30,7 @@ metadata:
name: test-pipeline-template
spec:
params:
- name: should-fail
- name: pr-id
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
@ -40,8 +40,8 @@ spec:
pipelineRef:
name: test-pipeline
params:
- name: should-fail
value: "$(tt.params.should-fail)"
- name: pr-id
value: "$(tt.params.pr-id)"
workspaces:
- name: shared-data
volumeClaimTemplate: