Fix organization loading error for PATs without read:org permission #1071
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
Users with GitHub Personal Access Tokens (PATs) that have repository access (
reposcope for classic tokens, orContents/Pull requestspermissions for fine-grained tokens) but lack organization listing permissions were encountering a blocking error when trying to create a new DAK:Error: "Error loading organizations"
This occurred because:
getUserOrganizations()API call requires theread:orgscope (classic tokens) orMembers: Read-onlypermission (fine-grained tokens)read:orgwas required for basic functionalitySolution
This PR implements graceful permission handling and improves documentation clarity:
1. Graceful Error Handling
Modified
getUserOrganizations()insrc/services/githubService.jsto:2. Improved Error Messages
Updated
OrganizationSelection.jsto show context-aware error messages:Before: "Failed to fetch organizations. Please check your connection and try again."
After: "Unable to list your organizations. Your Personal Access Token needs the 'read:org' scope (classic tokens) or 'Members: Read-only' permission (fine-grained tokens) to list organizations. You can still use your personal account or select WHO."
3. Documentation Clarity
Updated documentation to clarify that organization listing permission is optional:
read:org/Members: Read-onlyis only needed for listing organizationsAll documentation now clearly distinguishes between:
repo(classic) orContents+Pull requests(fine-grained) - for editing DAK contentread:org(classic) orMembers: Read-only(fine-grained) - only if you want to see organizations you're a member of4. Visual Enhancement
Added
.info-noteCSS class inPATSetupInstructions.cssfor displaying informational messages with proper styling (blue background, clear formatting) to distinguish from warnings and errors.5. Comprehensive Testing
Added 5 new tests in
src/services/githubService.test.js:All tests passing, no existing tests broken.
User Experience Impact
Before Fix
reposcope onlyAfter Fix
reposcope onlyBenefits
read:orglater if they need organization listingread:orgpermission experience no change in behaviorFiles Changed
src/services/githubService.js- Graceful error handlingsrc/components/OrganizationSelection.js- Improved error messageREADME.md- Clarified optional permissionsrc/components/PATSetupInstructions.js- Added info notesrc/components/PATSetupInstructions.css- Info note stylingsrc/components/PATLogin.js- Updated error messagesrc/services/githubService.test.js- Added comprehensive testsRelated Issue
Fixes issue reported by @costateixeira regarding PAT permissions and organization loading errors when creating new DAKs.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.