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
15 changes: 15 additions & 0 deletions .github/workflows/pr-archive-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ github.event.workflow_run.id }}
EVENT_PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}

steps:
# This trusted workflow reads artifact metadata only. Never download or
Expand All @@ -28,6 +29,20 @@ jobs:
run: |
set -euo pipefail

# workflow_run.pull_requests is populated only for same-repository pull
# requests and is empty for pull requests from forks, so fork builds never
# got past the check below. Match the head SHA from the trusted event
# payload against the open pull requests instead. The artifact name also
# encodes the number, but it is produced by the untrusted pull_request
# workflow, so it is not trusted to select the comment target here.
if [[ ! "$EVENT_PR_NUMBER" =~ ^[0-9]+$ ]]; then
EVENT_PR_NUMBER=$(
gh api "repos/$GITHUB_REPOSITORY/pulls?state=open&per_page=100" --paginate \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve fork PRs after they leave the open list

When a fork PR is merged or closed before its archive run completes, workflow_run.pull_requests is still empty but this query can no longer find the PR, so the following guard exits without posting the archive link. This is plausible because the archive job in pr-archive.yml may run for up to 45 minutes and closing a PR does not cancel its existing run; the fallback should also resolve matching closed/merged PRs while avoiding ambiguous SHA matches.

Useful? React with 👍 / 👎.

--jq '.[] | select(.head.sha == env.HEAD_SHA) | .number' \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Environment lookup returns no match

When a fork run has no event PR number, gh api --jq does not expose the shell's HEAD_SHA through env.HEAD_SHA, so the filter returns no PR number and the guard exits without posting the archive link.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/pr-archive-comment.yml
Line: 41

Comment:
**Environment lookup returns no match**

When a fork run has no event PR number, `gh api --jq` does not expose the shell's `HEAD_SHA` through `env.HEAD_SHA`, so the filter returns no PR number and the guard exits without posting the archive link.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Merge SHA cannot match head

For the upstream pull_request workflow, workflow_run.head_sha identifies the synthetic merge commit while .head.sha identifies the PR's actual head commit, so the fallback finds no PR and fork contributors still receive no archive link.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/pr-archive-comment.yml
Line: 41

Comment:
**Merge SHA cannot match head**

For the upstream `pull_request` workflow, `workflow_run.head_sha` identifies the synthetic merge commit while `.head.sha` identifies the PR's actual head commit, so the fallback finds no PR and fork contributors still receive no archive link.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

| sed -n '1p'
)
fi

if [[ ! "$EVENT_PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "The completed workflow run is not associated with a pull request." >&2
exit 1
Expand Down
Loading