Last active
December 6, 2019 16:16
-
-
Save dlorenc/2e24e7e0e30f98795be26c1cca49a737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment