Skip to content

Commit a1d4f9a

Browse files
dmytroyeCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 174b797 commit a1d4f9a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

.github/workflows/auto-update-labeled.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
--jq '.[] | @json')
4949
5050
if [[ ${#prs[@]} -eq 0 ]]; then
51-
echo "No open PRs with label '${UPDATE_LABEL}' target '${BASE_BRANCH}' — nothing to do."
51+
echo "No open PRs with label '${UPDATE_LABEL}' targeting '${BASE_BRANCH}' — nothing to do."
5252
exit 0
5353
fi
5454
@@ -92,14 +92,17 @@ jobs:
9292
GH_TOKEN: ${{ secrets.GH_PAT }}
9393
PR_NUMBER: ${{ github.event.pull_request.number }}
9494
run: |
95-
# Check if the label is present before attempting removal.
96-
has_label=$(gh pr view "$PR_NUMBER" \
95+
# Query labels first and fail explicitly if the GitHub CLI request fails.
96+
if ! pr_labels=$(gh pr view "$PR_NUMBER" \
9797
--repo "$GITHUB_REPOSITORY" \
9898
--json labels \
99-
--jq --arg lbl "$UPDATE_LABEL" '.labels[].name | select(. == $lbl)' \
100-
| grep -c . || true)
99+
--jq '.labels[].name'); then
100+
echo "Failed to read labels for PR #${PR_NUMBER}."
101+
exit 1
102+
fi
101103
102-
if [[ "$has_label" -eq 0 ]]; then
104+
# Treat a missing label as a normal no-op, but do not mask query failures.
105+
if ! printf '%s\n' "$pr_labels" | grep -Fxq -- "$UPDATE_LABEL"; then
103106
echo "PR #${PR_NUMBER} does not have the '${UPDATE_LABEL}' label — nothing to do."
104107
exit 0
105108
fi

0 commit comments

Comments
 (0)