File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -30,27 +30,35 @@ jobs:
3030
3131 function get_check_runs() {
3232 local endpoint=$1
33- curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" "$endpoint"
33+ local response
34+ response=$(curl -s -f -H "Authorization: Bearer ${GITHUB_TOKEN}" "$endpoint")
35+ if [ $? -ne 0 ]; then
36+ echo "Error fetching from $endpoint" >&2
37+ echo "{}"
38+ return 1
39+ fi
40+ echo "$response"
3441 }
3542
3643 function count_pending_checks() {
3744 local response=$1
38- echo "$response" | jq '[.check_runs[] | select(.status != "completed" and .name != "all-good")] | length'
45+ echo "$response" | jq '( [.check_runs[]? | select(.status != "completed" and .name != "all-good")] | length) // 0 '
3946 }
4047
4148 function count_failed_checks() {
4249 local response=$1
43- echo "$response" | jq '[.check_runs[] | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral" and .name != "all-good")] | length'
50+ echo "$response" | jq '( [.check_runs[]? | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != "neutral" and .name != "all-good")] | length) // 0 '
4451 }
4552
4653 while true; do
4754 commit_response=$(get_check_runs "https://api.github.com/repos/${REPO}/commits/${COMMIT}/check-runs")
48- commit_total=$(echo "$commit_response" | jq -r '.total_count')
55+ commit_total=$(echo "$commit_response" | jq -r '.total_count // 0 ')
4956
5057 # If this is a PR, also get PR check runs
58+ pr_total=0
5159 if [ -n "$PR_NUMBER" ]; then
5260 pr_response=$(get_check_runs "https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/check-runs")
53- pr_total=$(echo "$pr_response" | jq -r '.total_count')
61+ pr_total=$(echo "$pr_response" | jq -r '.total_count // 0 ')
5462 echo "Found ${commit_total} commit checks and ${pr_total} PR checks"
5563 else
5664 echo "Found ${commit_total} commit checks"
You can’t perform that action at this time.
0 commit comments