Repository navigation
ci: use pull_request_target in project-sync so fork PRs get board updates - #483
Merged
Merged
Conversation
…ates
GitHub withholds repository secrets from `pull_request` runs originating in a
fork, so PROJECT_TOKEN resolved to "" and gh exited 4 ("set the GH_TOKEN
environment variable") on the first API call. Board sync therefore failed for
every external contributor's PR (first seen on PR #482, from a fork).
pull_request_target runs in the base repo's context, where the secret is
available. Switch the trigger and update both PR job guards — link-pr-to-issue
(opened) and update-on-merge (closed) — since both authenticate with the PAT
and both were broken on forks.
pull_request_target is safe here only because the workflow never trusts fork
content: it does not check out PR code, and the fork-controlled values it reads
(PR title, head ref) already go through `env:` rather than being inlined into
`run:`. Also add workflow-level `permissions: {}` — every job uses the PAT, so
GITHUB_TOKEN needs no scopes. Documented the invariant in the trigger comment.
Note: pull_request_target loads the workflow from the base branch, so this takes
effect only once merged to main; it does not retroactively fix PR #482's run.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nockawa
added a commit
that referenced
this pull request
Jul 14, 2026
* ci: block closing keywords that would auto-close a pull request
GitHub scans a PR's description and its commit messages for a bare KEYWORD-then-
reference adjacency (close/closes/closed, fix/fixes/fixed, resolve/resolves/
resolved, immediately followed by #N) and closes item N on merge into the default
branch. Two properties make this a trap:
1. The parser has NO notion of negation. The phrase "does not retroactively
fix", immediately followed by "#N", links and closes item N exactly as if it
had read "fixes #N".
2. Pull requests and issues share one numbering space, so an N that happens to
be a PR closes that PR.
Both fired together: the body of PR #483 contained that negated phrasing followed
by a bare reference to the then-open PR #482, silently closing that unrelated
in-flight PR on merge. GitHub attributes such closes to whoever merged, so the
audit trail blamed a human who never clicked anything.
There is no repo/org/enterprise setting to disable closing keywords, so a check is
the only systemic defense. New `closing-keywords` job scans the same two surfaces
GitHub does and fails only when a keyword-linked number resolves to a pull request.
The everyday intended use -- a closing keyword naming a real issue -- stays green.
Surface handling mirrors GitHub's own parser:
- PR description is Markdown: fenced blocks and inline code spans are stripped
first, since GitHub does not parse references inside them. Without this the
guard flags any doc that merely quotes a keyword -- including the backticked
form the guard's own error message recommends.
- Commit messages are plain text: backticks do NOT defuse a keyword there, so
they are scanned raw. This matters because squash-merge concatenates every
commit message into the squash body.
Regex notes: the leading (^|[^[:alnum:]_]) is a word boundary -- without it
"postfix #N" trips on the trailing "fix". Spelled out rather than \b so it does
not rely on GNU-grep extensions. An intervening word (as in "fix PR #N") breaks
GitHub's adjacency rule and is correctly not matched here either.
Wired into the aggregate `gate` verdict; skipped on push/workflow_dispatch, where
there is no PR body to scan.
Verified: replays the incident (PR #483 -> RED, PR #482 -> GREEN), plus 15
positive/negative regex cases including the defusing forms the error suggests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* ci: don't fail clean PRs when no closing keyword is present
The step's shell is `bash -e` and the script adds pipefail, so the keyword grep
exiting 1 on NO match -- the healthy, common case -- propagated and killed the
script before it printed anything. Every clean PR went red; caught when this
branch's own PR failed its own check with zero output.
Guard the assignment with `|| true` and note why it must stay. Verified under
`bash -e` + pipefail: no-keyword -> exit 0, keyword-present -> detected.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Project Sync fails on every PR opened from a fork. First observed on #482 (failing run):
GitHub deliberately withholds repository secrets from
pull_requestruns that originate in a fork, sosecrets.PROJECT_TOKENresolved to""andghexited 4 on the first API call.This is not caused by anything in #482 — it affects any external contributor's PR. Prior Project Sync runs were all green only because they were
issuesevents from the same repo, so thelink-pr-to-issuejob had never run from an untrusted context before.Fix
Switch the trigger to
pull_request_target, which runs in the base repo's context where the secret is available.link-pr-to-issue(opened) andupdate-on-merge(closed). Both authenticate with the PAT, so both were broken on forks; changing only the first would have left the merge job silently dead.permissions: {}— every job usesPROJECT_TOKEN, soGITHUB_TOKENneeds no scopes at all.Why
pull_request_targetis safe hereIt's normally a repository-takeover footgun, so the constraints are documented in the trigger comment. It's sound in this workflow only because it never trusts fork content:
actions/checkout— attacker-supplied code is never fetched, let alone executed.env:and are never inlined into arun:body — the existing script-injection guard, which the original author had already got right.permissions: {}stripsGITHUB_TOKEN.Adding a checkout of the PR head, or inlining
${{ … }}of any user-controlled field into a shell body, would break this. The comment says so explicitly.Verification
grep: noactions/checkoutanywhere in the file; no stale barepull_requesttriggers left behind.github.event.pull_request.*references are correct — that payload object exists underpull_request_targettoo, and both are already routed viaenv:.Note
pull_request_targetloads the workflow from the base branch, so this only takes effect once merged tomain. It does not retroactively fix #482's red check — that run stays in the history.🤖 Generated with Claude Code