fix: properly check write access for fine-grained PATs #4
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
The
--postflag's write access check was incorrectly passing for tokens that lacked write permissions. This happened because the check only looked at the repositorypermissionsobject, 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
WriteAccessStatusenum (GRANTED,DENIED,UNCERTAIN) andWriteAccessResultmodel 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-Scopesresponse header:reposcoperepoorpublic_reposcope3. Fine-Grained PAT Live Test
For fine-grained PATs (which don't include scope info in headers), perform a live write test:
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:
Testing
All 58 tests pass with 84% coverage. Added tests for:
Files Changed
review_roadmap/models.py- Added WriteAccessStatus and WriteAccessResultreview_roadmap/github/client.py- Updated check_write_access with scope checking and live testreview_roadmap/main.py- Handle new result type, improved error messagestests/test_github_client.py- Comprehensive tests for all scenariostests/test_main.py- Updated mocks for new return typeREADME.md- Added GitHub token setup documentation