Repository navigation
fix: support fine-grained tokens in pr-review scope validation #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b765813
56171b2
271f738
43c260c
6d5ed78
da8fe6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,21 @@ tools: ["read", "edit", "search", "execute", "web"] | |
|
|
||
| You are the PR Review Agent for the petry-projects organization. | ||
|
|
||
| ## Required GitHub token scopes | ||
|
|
||
| The agent requires a GitHub personal access token (PAT) with these minimum permissions: | ||
|
|
||
| **Repository permissions:** | ||
| - `contents:read` β read file contents and diffs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the agent is configured to automatically approve and enable auto-merge (or merge) pull requests (as described in the Decision framework), a fine-grained token with only |
||
| - `pull_requests:write` β post reviews and comments on PRs | ||
| - `actions:read` β check CI status and workflow results | ||
| - `metadata:read` β read repository metadata | ||
|
|
||
| **Organization permissions:** | ||
| - `members:read` β read organization members for code owner routing | ||
|
|
||
| These are fine-grained token scopes. The legacy `repo` scope (which grants full repository control) is NOT required. | ||
|
|
||
|
|
||
| ## Your role | ||
|
|
||
| You review pull requests using a cascading tier system that minimizes token spend | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,39 +129,49 @@ | |
| **Invite member** β enter `donpetry-bot` β Role: **Member**. | ||
| 6. Accept the invite from the bot account. | ||
|
|
||
| ### 2. Create a **classic** PAT for the bot | ||
|
|
||
| > [!IMPORTANT] | ||
| > **Fine-grained PATs do not work for this workflow.** Use a classic PAT only. | ||
| > | ||
| > Fine-grained tokens are blocked by org policy gates: even after the org owner | ||
| > approves the token request and the bot has Write collaborator access, the | ||
| > GraphQL `addPullRequestReview` mutation fails with: | ||
| > | ||
| > ``` | ||
| > failed to create review: GraphQL: Resource not accessible by personal access token (addPullRequestReview) | ||
| > ``` | ||
| > | ||
| > If you see that error in a workflow run, the secret holds a fine-grained | ||
| > token. Replace it with a classic PAT generated as below. The same gate also | ||
| > blocks the rulesets bypass that branch protections rely on. | ||
| ### 2. Create a PAT for the bot (classic or fine-grained) | ||
|
|
||
| You can use either a **classic** or **fine-grained** PAT. Fine-grained tokens are | ||
| recommended for better security (principle of least privilege). | ||
|
|
||
|
Comment on lines
+132
to
+139
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine Grained PAT is working bot the pr-review agent
don-petry marked this conversation as resolved.
Resolved
|
||
| #### Option A: Fine-grained PAT (recommended) | ||
|
|
||
| 1. Sign in as the bot account (e.g. `donpetry-bot`) β sign out of `don-petry` | ||
| first, or use a private window. The PAT must be created **from the bot's | ||
| account**, not yours. | ||
| 2. Go to **Settings β Developer settings β Personal access tokens β | ||
| Tokens (classic)** β **Generate new token (classic)**. | ||
| Fine-grained tokens** β **Generate new token**. | ||
| 3. Settings: | ||
| - **Note:** `pr-review-agent` | ||
| - **Expiration:** 1 year (set a calendar reminder to rotate) | ||
| - **Scopes:** β `repo`, β `workflow`, β `read:org` | ||
| - **Token name:** `pr-review-agent` | ||
| - **Expiration:** 90 days (auto-rotate for security) | ||
| - **Resource owner:** select your organization (e.g. `petry-projects`) | ||
|
Comment on lines
+148
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's clear enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With this fine-grained setup, selecting Useful? React with πΒ / π. |
||
| - **Repository access:** All repositories (or specific repos if preferred) | ||
| - **Repository permissions:** | ||
| - `contents:read` β read files and diffs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the recommended fine-grained token is created with only Useful? React with πΒ / π. |
||
| - `pull_requests:write` β post reviews and comments | ||
| - `actions:read` β check CI status | ||
| - `metadata:read` β read repo metadata | ||
| - **Organization permissions:** | ||
| - `members:read` β read org members for code owner routing | ||
| 4. Generate and copy the token immediately. | ||
| 5. Sign back in as `don-petry` and store the token in the agent repo's secret | ||
| (the secret name is `DON_PETRY_BOT_GH_PAT` in `petry-projects/.github-private`). | ||
|
|
||
| After saving, trigger a workflow run and confirm the install step's | ||
| `gh auth status` reports the bot's login (not yours) and lists the three | ||
| scopes above. | ||
| #### Option B: Classic PAT (legacy) | ||
|
|
||
| If you prefer classic PATs or need broader scopes: | ||
|
|
||
| 1. Sign in as the bot account, go to **Settings β Developer settings β | ||
|
Check failure on line 164 in docs/pr-review-agent/pr-review-agent.md
|
||
| Personal access tokens β Tokens (classic)** β **Generate new token (classic)**. | ||
| 2. Settings: | ||
| - **Note:** `pr-review-agent` | ||
| - **Expiration:** 1 year | ||
| - **Scopes:** β `repo`, β `workflow`, β `read:org` | ||
| 3. Generate and store as `DON_PETRY_BOT_GH_PAT` (same as above). | ||
|
|
||
| After saving either token type, trigger a workflow run and confirm the | ||
| `gh auth status` output reports the bot's login (not yours) and lists the | ||
| required scopes. | ||
|
|
||
| > **Branch protection / rulesets:** add `donpetry-bot` as an allowed | ||
| > approver on each protected repo. In the repo ruleset or branch protection | ||
|
|
@@ -291,8 +301,8 @@ | |
| `petry-projects/.github` as `.github/workflows/pr-review-mention.yml`. | ||
|
|
||
| 2. Add the `DON_PETRY_BOT_GH_PAT` secret to `petry-projects/.github` | ||
| (org-level secret or repo secret on `.github`). Use a classic PAT from | ||
| `donpetry-bot` with scopes: β `repo`, β `workflow`, β `read:org` | ||
| (org-level secret or repo secret on `.github`). Use the same PAT created above | ||
| in [step 2](#2-create-a-pat-for-the-bot-classic-or-fine-grained). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an inconsistency between this documentation and the |
||
|
|
||
| 3. Ensure `donpetry-bot` has at least **Read** collaborator access on | ||
| `petry-projects/.github-private`. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For runs that actually use a fine-grained PAT, this validation still fails before any review starts because
gh auth statusexposes OAuth scopes from theToken scopes:line, not fine-grained repository permissions such ascontentsorpull_requests; GitHub CLIβs own auth docs describe fine-grained PATs as having inherent resource scoping, and the CLI maintainers note that fine-grained permission information is not readily available forghto detect. As a result, the recommended token path hits this loop with no matching scopes and exits 1 even when the token has the requested permissions; validate fine-grained tokens with a cheap API probe instead of checkingToken scopes:for permission names.Useful? React with πΒ / π.