From ac3188192716c713404d5ecdb243515879a5fb5a Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Fri, 24 Jul 2026 12:24:33 -0500 Subject: [PATCH] Improve error handling in post-cdash-status --- post-cdash-status | 52 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/post-cdash-status b/post-cdash-status index 85ae473..c472aea 100755 --- a/post-cdash-status +++ b/post-cdash-status @@ -1,7 +1,5 @@ #!/bin/bash -set -eo pipefail - readonly API_BASE="https://api.github.com/repos/${GITHUB_REPOSITORY}" function require_cmd() { @@ -28,12 +26,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 \ + -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 1 +fi post_body="$(cat<