Skip to content

Commit 46ffb21

Browse files
authored
Merge pull request #27 from actions/fix/report-gh-pr-lookup-errors
Report pull request lookup failures
2 parents d8e3291 + f7cadd5 commit 46ffb21

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ permissions:
3636
```
3737

3838
For push-only workflows where the action looks up PR numbers via `gh pr list`, also add `pull-requests: read`.
39+
The runner must have the GitHub CLI installed. GitHub-hosted runners include it by default.
3940

4041
## Error handling
4142

‎action.yml‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ runs:
6262
else
6363
COMMIT_OID="${{ github.sha }}"
6464
REF="${{ github.ref }}"
65-
PR_NUMBER=$(gh pr list \
66-
--repo "$GITHUB_REPOSITORY" \
67-
--head "${{ github.ref_name }}" \
68-
--state open \
69-
--json number \
70-
--jq '.[0].number // empty' 2>/dev/null || true)
65+
if ! PR_NUMBER=$(gh pr list \
66+
--repo "$GITHUB_REPOSITORY" \
67+
--head "${{ github.ref_name }}" \
68+
--state open \
69+
--json number \
70+
--jq '.[0].number // empty'); then
71+
echo "::error::Failed to query pull requests using the GitHub CLI. Ensure gh is installed and the workflow grants pull-requests: read permission."
72+
exit 1
73+
fi
7174
fi
7275
7376
COMMIT_OID="$COMMIT_OID" \

0 commit comments

Comments
 (0)