Skip to content

Commit d7f3893

Browse files
committed
Improve error handling in onboarding workflow by validating GitHub API responses when listing branches, ensuring robust detection of empty repositories.
1 parent 1db4d46 commit d7f3893

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

.github/workflows/onboard-new-repo.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@ jobs:
112112
if: steps.check_opt_out.outputs.opted_out != 'true'
113113
id: check_empty
114114
run: |
115-
# Try to list branches in the repository
116-
BRANCHES=$(gh api "repos/$REPO/branches" --jq 'length' 2>/dev/null) || BRANCHES="0"
115+
if ! BRANCHES=$(gh api "repos/$REPO/branches" --jq 'length' 2>&1); then
116+
echo "::error::GitHub API call failed while listing branches for $REPO: $BRANCHES"
117+
exit 1
118+
fi
119+
120+
if ! echo "$BRANCHES" | grep -qE '^[0-9]+$'; then
121+
echo "::error::Unexpected API response when listing branches for $REPO: $BRANCHES"
122+
exit 1
123+
fi
117124
118-
# If there are no branches, the repo is empty
119125
if [ "$BRANCHES" = "0" ]; then
120126
IS_EMPTY="true"
121127
echo "Repository is empty (no branches found)"

0 commit comments

Comments
 (0)