Skip to content

Conversation

@jwm4
Copy link
Collaborator

@jwm4 jwm4 commented Jan 2, 2026

Problem

The --post flag's write access check was incorrectly passing for tokens that lacked write permissions. This happened because the check only looked at the repository permissions object, which reflects the user's access level rather than the token's specific permissions.

For example, if a user has push access to a repository but their fine-grained PAT is only configured for a different repo, the check would pass but the actual post would fail with 403.

Solution

1. Structured Access Check Results

Added WriteAccessStatus enum (GRANTED, DENIED, UNCERTAIN) and WriteAccessResult model to provide detailed feedback about the access check.

2. Classic PAT Verification

For classic PATs and OAuth tokens, verify OAuth scopes via the X-OAuth-Scopes response header:

  • Private repos require repo scope
  • Public repos accept repo or public_repo scope

3. Fine-Grained PAT Live Test

For fine-grained PATs (which don't include scope info in headers), perform a live write test:

  • Create an "eyes" (👀) reaction on the PR
  • Immediately delete it
  • This verifies actual write access without leaving any artifacts

4. Improved Error Messages

Better error messages with troubleshooting guidance when access is denied.

5. Documentation

Added comprehensive "GitHub Token Setup" section to README explaining:

  • Token types and their permissions
  • Step-by-step instructions for creating tokens
  • The difference between user permissions and token scopes

Testing

All 58 tests pass with 84% coverage. Added tests for:

  • Classic PAT scope verification (various scenarios)
  • Fine-grained PAT live write test (success and failure)
  • Fine-grained PAT without PR number (returns UNCERTAIN)

Files Changed

  • review_roadmap/models.py - Added WriteAccessStatus and WriteAccessResult
  • review_roadmap/github/client.py - Updated check_write_access with scope checking and live test
  • review_roadmap/main.py - Handle new result type, improved error messages
  • tests/test_github_client.py - Comprehensive tests for all scenarios
  • tests/test_main.py - Updated mocks for new return type
  • README.md - Added GitHub token setup documentation

jwm4 added 2 commits January 2, 2026 15:51
Update remaining references to the old jwm4 repo:
- review_roadmap/main.py: footer link in generated roadmaps
- tests/test_main.py: test assertion for footer URL
- ADR/phase4_plan.md: pip install example URL
The write access check was incorrectly passing for tokens that lacked
write permissions because it only checked the repository permissions
object, which reflects user access rather than token-specific access.

Changes:
- Add WriteAccessStatus enum and WriteAccessResult model for detailed
  access check results (GRANTED, DENIED, UNCERTAIN)
- For classic PATs: verify OAuth scopes via X-OAuth-Scopes header
- For fine-grained PATs: perform live write test using reactions
  (create and immediately delete an 'eyes' reaction on the PR)
- Improve error messages with troubleshooting guidance
- Add comprehensive GitHub token setup documentation to README

The live write test allows definitive verification for fine-grained PATs,
which cannot be checked via headers since they don't include scope info
and the permissions object reflects user access, not token configuration.
@jwm4 jwm4 merged commit e4ba4c0 into main Jan 2, 2026
1 check passed
@jwm4 jwm4 deleted the fix/write-access-check-for-fine-grained-pats branch January 2, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants