Skip to content

Commit cfd4ce9

Browse files
committed
Fix /review trigger: gate JSON parse + reaction permission scope
Two independent bugs prevented the PR review workflow from running on /review comments: 1. gate.py used gh_json() to fetch the commenter's permission level, but 'gh api ... -q .permission' returns a bare token (e.g. 'admin'), not JSON. json.loads() raised JSONDecodeError, which was swallowed by the broad except and treated as 'no write access'. Every commenter, including admins, was rejected. Switched to gh() and compare the raw stdout instead. 2. The dispatch job declared 'issues: write' + 'pull-requests: read', but POSTing a reaction to a PR-issue comment requires 'pull-requests: write' on the GITHUB_TOKEN (the URL is /issues/comments/.../reactions, but the resource is a PR comment). The 'React eyes' step returned HTTP 403 'Resource not accessible by integration'. Swapped the scopes.
1 parent ccd1942 commit cfd4ce9

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

.github/scripts/pr-review/gate.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import sys
2121
from pathlib import Path
2222

23-
from common import gh_json, progress
23+
from common import gh, gh_json, progress
2424

2525

2626
REVIEW_RE = re.compile(r"^/review(?:\s+(\S+))?\s*$")
@@ -72,13 +72,15 @@ def commenter_has_write_access(repo: str, login: str) -> bool:
7272
# on transient gh/API failures, which is the safer default for a gate
7373
# that controls whether the reviewer agent runs.
7474
try:
75-
result = gh_json(
75+
# `gh api ... -q .permission` returns a bare string (e.g. "admin"),
76+
# not JSON, so we use `gh` directly and read stdout rather than
77+
# `gh_json` (which would JSONDecodeError on the bare token).
78+
result = gh(
7679
["api", f"repos/{repo}/collaborators/{login}/permission", "-q", ".permission"],
7780
)
7881
except Exception:
7982
return False
80-
# gh_json returns parsed JSON; with -q the output is a bare string.
81-
return result in {"admin", "write"}
83+
return result.stdout.strip() in {"admin", "write"}
8284

8385

8486
class SkipRun(Exception):

.github/workflows/pr-review.lock.yml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/pr-review.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ jobs:
7171
runs-on: ubuntu-latest
7272
permissions:
7373
contents: read
74-
pull-requests: read
75-
issues: write # for reactions on the triggering comment
74+
pull-requests: write # for reactions on the triggering PR comment
75+
issues: read
7676
outputs:
7777
should_run: ${{ steps.gate.outputs.should_run }}
7878
pr_number: ${{ steps.gate.outputs.pr_number }}

0 commit comments

Comments
 (0)