forked from dlorenc/tekton-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-task.yaml
69 lines (66 loc) · 1.79 KB
/
chatbot-task.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: chatbot-task
spec:
inputs:
resources:
- name: repo
type: git
- name: pr
type: pullRequest
params:
- name: comment
type: string
- name: author_association
type: string
outputs:
resources:
- name: pr
type: pullRequest
steps:
- name: copy-pr
image: ubuntu
command: ["/bin/sh"]
args:
- -c
- cp -r /workspace/pr/ /workspace/output/
- name: run-command
image: gcr.io/cloud-builders/git
command: ["/bin/bash"]
args:
- -c
- |
set -ex
# Skip if the PR was not opened by an OWNER
author="$(inputs.params.author_association)"
if [[ "$author" -ne "OWNER" ]]; then
echo "Skipping PR, author is not an OWNER: $author"
exit 0
fi
# Get the PR number from the PR URL.
prurl="$(inputs.resources.pr.url)"
prNum=$(echo "$prurl" | awk -F/ '{print $NF}')
comment="$(inputs.params.comment)"
msg=""
case $comment in
"/chatbot test" )
cd /workspace/repo
# Checkout the PR branch
git fetch origin refs/pull/$prNum/head:pull_$prNum
git checkout pull_$prNum
# Run tests
output=$(./test.sh)
code=$?
msg="Tests Passed."
if [[ $code -ne 0 ]]; then
msg="Tests Failed. Output: $output"
fi;;
/chatbot* )
msg="Usage: /chatbot \<command\>. Current commands are: test";;
* )
echo "skipping command $comment, does not start with /chatbot prefix";;
esac
if [[ ! -z "$msg" ]]; then
echo "$msg" > /workspace/output/pr/comments/new
fi