Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions .github/workflows/pr-review-mention-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,35 @@ jobs:
if: steps.trust.outputs.trusted == 'true'
env:
GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }}
# Resolve by event name: review_requested and review-comment payloads
# expose the PR directly; only issue_comment needs a gh api round-trip.
# Guard the empty case so we never call `gh api ""` (#500).
EVENT_NAME: ${{ github.event_name }}
PR_HTML_URL: ${{ github.event.pull_request.html_url }}
ISSUE_PR_API_URL: ${{ github.event.issue.pull_request.url }}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
PR_URL="${{ github.event.pull_request.html_url }}"
elif [ "${{ github.event_name }}" = "pull_request_review_comment" ]; then
PR_URL="${{ github.event.pull_request.html_url }}"
else
# issue_comment: resolve the PR URL from the issue's pull_request link
PR_URL=$(gh api "${{ github.event.issue.pull_request.url }}" --jq '.html_url')
case "$EVENT_NAME" in
pull_request | pull_request_review_comment)
PR_URL="$PR_HTML_URL"
;;
issue_comment)
if [ -z "$ISSUE_PR_API_URL" ]; then
echo "resolve-pr-url: issue_comment event has no pull_request url (not a PR comment)" >&2
exit 1
fi
PR_URL="$(gh api "$ISSUE_PR_API_URL" --jq '.html_url')" || {
echo "resolve-pr-url: failed to retrieve PR URL from GitHub API using '$ISSUE_PR_API_URL'" >&2
exit 1
}
;;
*)
echo "resolve-pr-url: unsupported event '$EVENT_NAME'" >&2
exit 1
;;
esac
if [ -z "$PR_URL" ] || [ "$PR_URL" = "null" ]; then
echo "resolve-pr-url: could not resolve a PR url for event '$EVENT_NAME'" >&2
exit 1
fi
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
echo "PR URL: $PR_URL"
Expand Down
Loading