Use heredocs instead of jq.

This commit is contained in:
jimmy committed 2023-01-31 20:17:19 -05:00
1 parent fc6a3c9c63
commit b373fca18c
4 files changed
+101 -13

No files matched your search

+15 -6
View File
@@ -16,20 +16,29 @@ spec:
#!/usr/bin/env bash
set -e
function make_request {
cat <<EOF > request.json
{
"projectId": $(params.project-id),
"title": "Failed run: $(params.run-name).",
"description": "Build Failed!",
"confidential": false,
"milestoneIds": [],
"fields": {"Type": "Build Failure"}
}
EOF
}
case "$(params.status)" in
"Succeeded" | "Completed")
echo "Build was successful!"
;;
"Failed" | "None")
echo "Build failed. :("
echo '{"projectId": 0, "title": "", "description": "Build Failed!",
"confidential": false, "milestoneIds": [],
"fields": {"Type": "Build Failure"} }' > request1.json
cat request1.json | jq ".projectId = $(params.project-id)" | jq . > request2.json
cat request2.json | jq ".title = \"Failed run: $(params.run-name).\" " | jq . > request3.json
make_request
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@request3.json \
-d@request.json \
$(params.feedback-url)/~api/issues
;;
esac
+9 -7
View File
@@ -28,15 +28,17 @@ spec:
esac
# 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 = \"$STATUS Tekton run: $(params.run-name).\"" | jq . > comment4.json
cat <<EOF > comment.json
{
"userId": $TEKTON_USER_ID,
"requestId": $(params.pr-id),
"date": "`date +"%Y-%m-%dT%H:%M:%S%:z"`",
"content": "$STATUS Tekton run: $(params.run-name)."
}
EOF
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@comment4.json \
-d@comment.json \
$(params.feedback-url)/~api/pull-request-comments
env:
- name: TEKTON_API_KEY