Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions post-cdash-status
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,27 @@ require_env_var "GITHUB_TOKEN"

#==============================================================================

statuses=$(curl -q -s \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${API_BASE}/commits/${COMMIT_SHA}/statuses" |\
jq -r '[.[].context] | @json')
readonly status_response=$(
curl -q -s \
Comment thread
hainest marked this conversation as resolved.
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${API_BASE}/commits/${COMMIT_SHA}/statuses")

# The API returns an empty array if no statuses were found
# This can happen if the COMMIT_SHA doesn't point to the head of the branch/PR
if [ "true" == $(jq -r '. == []' <<<$status_response) ]; then
echo "No statuses found for '${API_BASE}/commits/${COMMIT_SHA}'"
exit 1
fi

readonly statuses=$(jq -r '[.[].context] | @json' <<< $status_response)
if [ -z "$statuses" ]; then
echo "Failed to parse statuses for '${API_BASE}/commits/${COMMIT_SHA}'"
echo -e "Request returned:\n$status_response"
exit 2
fi

post_body="$(cat<<EOF
{
Expand All @@ -47,13 +62,22 @@ EOF

post_url="${API_BASE}/statuses/${COMMIT_SHA}"

if jq -re "all(. != \"${GITHUB_STATUS_NAME}\")" <<<"${statuses}"; then
if [ "true" == $(jq -re "all(. != \"${GITHUB_STATUS_NAME}\")" <<<"${statuses}") ]; then
echo "Need to post a status for context ${GITHUB_STATUS_NAME}"

curl -X POST -q -s \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d "${post_body}" "${post_url}"
readonly response=$(
curl -X POST -q -s \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d "${post_body}" "${post_url}")

if [ "false" == $(jq -r 'has("creator")') <<<"$response" ]; then
echo "Failed to create status for '${API_BASE}/commits/${COMMIT_SHA}'"
echo -e "Request returned:\n$response"
exit 3
fi
else
echo "No status updates needed."
fi
Loading