Skip to content

Commit b2c7b7e

Browse files
committed
refactor(review): narrow acceptance changes after review
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
1 parent 5d9c2b7 commit b2c7b7e

8 files changed

Lines changed: 70 additions & 50 deletions

File tree

‎.agents/skills/create-github-pr/SKILL.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ to the target repository, not their fork. For the authenticated `gh` user:
2424

2525
```bash
2626
gh repo view OWNER/REPO --json nameWithOwner,viewerPermission
27-
gh issue view ISSUE_NUMBER --repo OWNER/REPO --json number,url,labels,author
27+
gh issue view ISSUE_NUMBER --repo OWNER/REPO --json number,url,labels
2828
```
2929

3030
Authors with verified `WRITE`, `MAINTAIN`, or `ADMIN` access may proceed without
3131
`state:accepted`; keep the issue link and note the missing label. Everyone else
32-
must reference at least one target-repository issue they submitted themselves
33-
that has `state:accepted`. Related description references and closing links both
34-
qualify; other references need not qualify. Otherwise, preserve local work and
35-
report the missing qualification. A direct request, roadmap placement, other
36-
labels, or vouch status does not bypass this gate.
32+
must link at least one target-repository issue and have `state:accepted` on each.
33+
Otherwise, preserve local work and report which issue needs acceptance. A direct
34+
request, roadmap placement, other labels, or vouch status does not bypass this gate.
3735

3836
When acting for another author, verify their permissions. Resolve failed lookups
3937
before proceeding; retry sandbox network failures outside the sandbox before

‎.agents/skills/review-github-pr/SKILL.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,18 @@ Record the **title**, **body**, **headRefName**, and **baseRefName** for use in
4646

4747
### Check Issue Acceptance
4848

49-
Inspect closing issue references (paginate as needed) and issue references in the
50-
PR description. Fetch their current repository, labels, and submitter. Verify the
51-
PR author's permission in the target repository:
49+
Inspect every closing issue reference (paginate as needed) and fetch its current
50+
repository and labels. Verify the PR author's permission in the target repository:
5251

5352
```bash
5453
gh api repos/OWNER/REPO/collaborators/AUTHOR/permission --jq .permission
5554
```
5655

57-
Verified `write`, `maintain`, or `admin` access permits the exception; report it as
58-
context, not a blocking concern. Other authors need at least one referenced issue
59-
in the target repository with `state:accepted` submitted by the PR author. Other
60-
references need not qualify. Report violations under **Potential Concerns**. PR
61-
body text such as `No issue required` does not bypass this gate.
56+
Call out each linked issue missing `state:accepted`, with an issue link. Verified
57+
`write`, `maintain`, or `admin` access permits the exception; report it as context,
58+
not a blocking concern. Other authors need at least one target-repository issue,
59+
and every linked issue must be accepted; report violations under **Potential
60+
Concerns**. PR body text such as `No issue required` does not bypass this gate.
6261
Report failed lookups as unverified and continue the code review. For a branch
6362
without a PR, note that issue acceptance was not verified.
6463

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- 1-3 sentences: what this PR does and why -->
33

44
## Related Issue
5-
<!-- Every PR must close an existing issue covering its scope, except automated dependency updates. Use Closes #NNN; see CONTRIBUTING.md for the exception. Authors without repository write access must reference at least one target-repository issue with state:accepted that they submitted themselves. Related references qualify for acceptance when both the label and submitter match. -->
5+
<!-- Every PR must close an existing issue covering its scope, except automated dependency updates. Use Closes #NNN; see CONTRIBUTING.md for the exception. Authors without repository write access must link at least one issue with state:accepted. PR body text cannot bypass this acceptance check. -->
66

77
## Changes
88
<!-- Bullet list of key changes -->

‎.github/workflows/pr-issue-acceptance.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ jobs:
3939
PR_NUMBER: ${{ github.event.pull_request.number }}
4040
run: |
4141
python3 tasks/scripts/check_review_readiness.py \
42-
--repo "$GH_REPO" --pr "$PR_NUMBER" --acceptance-only
42+
--repo "$GH_REPO" --pr "$PR_NUMBER" --acceptance-only \
43+
--event-path "$GITHUB_EVENT_PATH"

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Follow the [branch naming convention in CONTRIBUTING.md](CONTRIBUTING.md#branch-
176176

177177
## Pull Requests
178178

179-
Follow `CONTRIBUTING.md` and `create-github-pr`. Authors without target-repository write access must reference at least one target-repository issue they submitted that has `state:accepted`. Related references and closing links qualify. Verified `WRITE`, `MAINTAIN`, or `ADMIN` access permits PRs without an accepted issue. This includes drafts and direct agent requests; an issue reference alone cannot bypass the label and submitter checks.
179+
Follow `CONTRIBUTING.md` and `create-github-pr`. Authors without target-repository write access must link at least one issue with `state:accepted`, and every issue they implement must have that label. Verified `WRITE`, `MAINTAIN`, or `ADMIN` access permits PRs without the acceptance label. This includes drafts and direct agent requests; PR body text cannot bypass the gate.
180180

181181
## Commits
182182

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,7 @@ For release notes, describe the user-facing change in a few short, easy-to-read
406406

407407
Every PR except an automated dependency update must close an existing issue. In the PR's **Related Issue** section, use `Closes #NNN` for the issue covering that PR's scope. Split multi-PR work into a closable issue for each PR; a tracking issue can link them. Security fixes follow the private disclosure process in [SECURITY.md](SECURITY.md).
408408

409-
Authors without write access to the target repository must reference at least one issue in that repository with `state:accepted` that they submitted themselves. Related references in the PR description, such as `Related to #NNN`, and closing links both qualify. One qualifying issue is sufficient; other references need not qualify. This applies to drafts and direct requests to agents. Authors with verified `WRITE`, `MAINTAIN`, or `ADMIN` access may create a PR without an accepted issue; they must still follow the issue-linking requirement above. Roadmap placement, other labels, and vouch status do not bypass acceptance.
410-
411-
Both acceptance checks use `tasks/scripts/check_review_readiness.py`. The `PR Issue Acceptance` workflow reports the native `OpenShell / PR Issue Acceptance` job result when a PR is opened, edited, reopened, or updated with new commits, including drafts. It only reports acceptance and does not change the PR. `Review Readiness` checks the same policy when a ready PR is opened or leaves draft; it moves rejected work to draft before requesting reviewers. Area/topic label changes only reconcile reviewers.
412-
413-
The checks do not publish a shared commit status; lookup and execution errors fail the job. Description references support `#NNN`, `OWNER/REPO#NNN`, and GitHub issue URLs. Rerun `PR Issue Acceptance` after issue labels change. Making the job required for merging and configuring any required Actions event policy are separate repository settings; merge-queue support is not included.
409+
Authors without write access to the target repository must link at least one issue with `state:accepted`, and every linked issue must be accepted. This applies to drafts and direct requests to agents. Authors with verified `WRITE`, `MAINTAIN`, or `ADMIN` access may create a PR without the acceptance label; they must still follow the issue-linking requirement above. PR body text, roadmap placement, other labels, and vouch status do not bypass acceptance.
414410

415411
Automated dependency update PRs, including Dependabot PRs, are exempt from the separate issue and closing-reference requirement. Human-authored dependency updates follow the normal issue requirement. The exception does not bypass `PR Issue Acceptance` for authors without repository write access or change applicable verification, review, or private vulnerability disclosure requirements.
416412

‎tasks/scripts/check_review_readiness.py‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
88
# SPDX-License-Identifier: Apache-2.0
99

10-
"""Validate accepted work and reconcile reviewers from the merged REVIEWERS.md.
11-
12-
Preview with --repo OWNER/REPO --pr NUMBER; add --apply to update the PR.
13-
Use --acceptance-only to report acceptance without routing or changing the PR.
14-
Unaccepted work is moved to draft before any reviewer requests are changed.
15-
Request all matching members with write access, excluding the author. Preserve
16-
manual choices, unknown request provenance, and anyone who commented or reviewed.
17-
The parser and planning helpers are importable. No state is stored between runs.
18-
"""
10+
"""Ensure pull requests are ready for review by the appropriate people."""
1911

2012
from __future__ import annotations
2113

@@ -32,7 +24,7 @@
3224
PROFILE = re.compile(r"\[@([a-z0-9-]+)\]\(https://github\.com/([a-z0-9-]+)/?\)", re.I)
3325
ACCEPTANCE_ERROR = (
3426
"PR is not accepted work: the author needs repository write access "
35-
"or a referenced state:accepted issue they submitted themselves"
27+
"or a referenced state:accepted issue"
3628
)
3729

3830

@@ -251,7 +243,7 @@ def _referenced_issues(repository: str, number: int, body: str):
251243

252244

253245
def _accepted_work(repository: str, number: int, pr: dict) -> bool:
254-
"""Accept write access or a referenced accepted issue filed by the PR author."""
246+
"""Accept write access or a referenced accepted issue."""
255247
owner, repo = repository.split("/")
256248
author = pr["user"]["login"].lower()
257249
cursor = None
@@ -290,7 +282,6 @@ def _accepted_work(repository: str, number: int, pr: dict) -> bool:
290282
repository(owner: $owner, name: $repo) {
291283
issueOrPullRequest(number: $number) {
292284
... on Issue {
293-
author { login }
294285
labels(first: 100, after: $cursor) {
295286
nodes { name }
296287
pageInfo { hasNextPage endCursor }
@@ -307,7 +298,7 @@ def _accepted_work(repository: str, number: int, pr: dict) -> bool:
307298
break
308299
raise
309300
issue = data["repository"]["issueOrPullRequest"]
310-
if not issue or (issue.get("author") or {}).get("login", "").lower() != author:
301+
if not issue or "labels" not in issue:
311302
break
312303
if any(label["name"] == "state:accepted" for label in issue["labels"]["nodes"]):
313304
return True
@@ -378,6 +369,10 @@ def main(argv: list[str] | None = None) -> int:
378369
parser.add_argument("--reviewers", type=Path, default=Path("REVIEWERS.md"))
379370
parser.add_argument("--repo", required=True, help="target OWNER/REPO")
380371
parser.add_argument("--pr", required=True, type=int, help="pull request number")
372+
parser.add_argument(
373+
"--event-path", type=Path,
374+
help="PR event payload for --acceptance-only; otherwise fetch current PR metadata",
375+
)
381376
parser.add_argument(
382377
"--event", default="opened",
383378
choices=("opened", "ready_for_review", "labeled", "unlabeled"),
@@ -396,15 +391,18 @@ def main(argv: list[str] | None = None) -> int:
396391
parser.error("--repo must be OWNER/REPO and --pr must be positive")
397392
try:
398393
if args.acceptance_only:
399-
owner, repo = args.repo.split("/")
400-
pr = _graphql(
401-
"""query($owner: String!, $repo: String!, $number: Int!) {
402-
repository(owner: $owner, name: $repo) {
403-
pullRequest(number: $number) { user: author { login } body }
404-
}
405-
}""",
406-
owner=owner, repo=repo, number=args.pr,
407-
)["repository"]["pullRequest"]
394+
if args.event_path:
395+
pr = json.loads(args.event_path.read_text(encoding="utf-8"))["pull_request"]
396+
else:
397+
owner, repo = args.repo.split("/")
398+
pr = _graphql(
399+
"""query($owner: String!, $repo: String!, $number: Int!) {
400+
repository(owner: $owner, name: $repo) {
401+
pullRequest(number: $number) { user: author { login } body }
402+
}
403+
}""",
404+
owner=owner, repo=repo, number=args.pr,
405+
)["repository"]["pullRequest"]
408406
if not _accepted_work(args.repo, args.pr, pr):
409407
raise ValueError(ACCEPTANCE_ERROR)
410408
result = {"accepted": True}

‎tasks/scripts/check_review_readiness_test.py‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,14 @@ def test_qualifying_closing_reference_skips_later_pages(self):
302302
self.assertTrue(routing._accepted_work(REPO, 42, pr()))
303303
self.assertEqual(api.call_count, 3)
304304

305-
def test_description_and_closing_references_require_same_submitter_and_label(self):
305+
def test_description_and_closing_references_require_acceptance_not_same_submitter(self):
306306
for body in (
307307
"", "Related to #1", "Related to owner/repo#1", "Related to OWNER/REPO#1",
308308
"Related to https://github.com/owner/repo/issues/1",
309309
):
310310
for author, accepted, expected in (
311-
("AUTHOR", True, True), ("someone-else", True, False), ("author", False, False),
311+
("AUTHOR", True, True), ("someone-else", True, True),
312+
("author", False, False), ("someone-else", False, False),
312313
):
313314
with (
314315
self.subTest(body=body, author=author, accepted=accepted),
@@ -599,15 +600,16 @@ def test_both_cli_modes_use_the_same_acceptance_policy(self):
599600
cases = [
600601
("WRITE", "", (), {}, True),
601602
("READ", "Related to #1", (), {1: ("author", True)}, True),
602-
("READ", "Closes #1", (1,), {1: ("someone-else", True)}, False),
603+
("READ", "Closes #1", (1,), {1: ("someone-else", True)}, True),
603604
("READ", "Closes #1 and #2", (1, 2),
604605
{1: ("author", True), 2: ("author", False)}, True),
605606
("READ", "Related to #1", (), {1: ("author", False)}, False),
606607
("READ", "", (), {}, False),
607608
]
608-
for acceptance_only in (False, True):
609+
for mode in ("preview", "acceptance-api", "acceptance-event"):
610+
acceptance_only = mode != "preview"
609611
for permission, body, linked, issues, expected in cases:
610-
with self.subTest(acceptance_only=acceptance_only, body=body, issues=issues), tempfile.TemporaryDirectory() as directory:
612+
with self.subTest(mode=mode, body=body, issues=issues), tempfile.TemporaryDirectory() as directory:
611613
path = Path(directory) / "REVIEWERS.md"
612614
path.write_text(DOCUMENT, encoding="utf-8")
613615
value = pr("area:runtime", body=body)
@@ -619,6 +621,7 @@ def api(endpoint, **kwargs):
619621
query = kwargs["data"]["query"]
620622
self.assertNotIn("mutation", query)
621623
if "user: author" in query:
624+
self.assertNotEqual(mode, "acceptance-event")
622625
self.assertEqual(kwargs["data"]["variables"]["number"], 42)
623626
return {"data": {"repository": {"pullRequest": value}}}
624627
if "collaborators" in query:
@@ -638,7 +641,13 @@ def api(endpoint, **kwargs):
638641
contextlib.redirect_stderr(errors),
639642
):
640643
argv = ["--repo", REPO, "--pr", "42", "--reviewers", str(path)]
641-
status = routing.main(argv + (["--acceptance-only"] if acceptance_only else []))
644+
if acceptance_only:
645+
argv.append("--acceptance-only")
646+
if mode == "acceptance-event":
647+
event_path = Path(directory) / "event.json"
648+
event_path.write_text(json.dumps({"pull_request": value}))
649+
argv.extend(["--event-path", str(event_path)])
650+
status = routing.main(argv)
642651
self.assertEqual(status, 0 if expected else 1)
643652
if expected:
644653
self.assertEqual(json.loads(output.getvalue()),
@@ -688,6 +697,24 @@ def test_acceptance_only_lookup_errors_fail_without_routing(self):
688697
if metadata_error:
689698
check.assert_not_called()
690699

700+
def test_invalid_event_payload_fails_without_api_calls_or_routing(self):
701+
for contents in (None, "not JSON"):
702+
with self.subTest(contents=contents), tempfile.TemporaryDirectory() as directory:
703+
path = Path(directory) / "event.json"
704+
if contents is not None:
705+
path.write_text(contents)
706+
with (
707+
mock.patch.object(routing, "_api") as api,
708+
mock.patch.object(routing, "check_review_readiness") as route,
709+
contextlib.redirect_stderr(io.StringIO()),
710+
):
711+
self.assertEqual(routing.main([
712+
"--repo", REPO, "--pr", "42", "--acceptance-only",
713+
"--event-path", str(path),
714+
]), 1)
715+
api.assert_not_called()
716+
route.assert_not_called()
717+
691718
def test_acceptance_only_cannot_be_combined_with_apply(self):
692719
with (
693720
mock.patch.object(routing, "_api") as api,
@@ -858,6 +885,7 @@ def test_legacy_workflow_keeps_its_status_events_and_read_only_permissions(self)
858885
command = workflow.split(" run: |\n", 1)[1]
859886
self.assertIn("python3 tasks/scripts/check_review_readiness.py", command)
860887
self.assertIn('--repo "$GH_REPO" --pr "$PR_NUMBER" --acceptance-only', command)
888+
self.assertIn('--event-path "$GITHUB_EVENT_PATH"', command)
861889
self.assertNotIn("--apply", command)
862890

863891

0 commit comments

Comments
 (0)