Fix organization loading error for PATs without read:org permission#1071
Draft
Fix organization loading error for PATs without read:org permission#1071
Conversation
- Handle missing read:org permission gracefully in getUserOrganizations() - Return empty array instead of throwing when org permission is missing - Update error message to guide users on missing permission - Clarify that read:org/Members permission is optional in documentation - Update README, PATSetupInstructions, and PATLogin error messages Co-authored-by: litlfred <662242+litlfred@users.noreply.github.com>
- Test successful organization retrieval with proper permissions - Test graceful handling of 403/401 permission errors (returns empty array) - Test error throwing for non-permission errors (network issues) - Test authentication requirement - All 5 new tests passing Co-authored-by: litlfred <662242+litlfred@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error loading organizations when creating new DAK
Fix organization loading error for PATs without read:org permission
Oct 9, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.