-
Notifications
You must be signed in to change notification settings - Fork 8
Fix private repository listing returning empty results #537
Description
Context
Get-GitHubRepository is used to list repositories filtered by visibility. Organization administrators and individual users rely on this to enumerate private (and internal) repositories for audit, automation, and governance workflows.
Request
When calling Get-GitHubRepository -Visibility Private (or -Visibility Internal), the command returns an empty list — even when the authenticated user has access to private repositories in their account or organization.
Reproduction steps
# Authenticated as a user with private repos
Get-GitHubRepository -Visibility Private
# Returns: (no output)
Get-GitHubRepository -Visibility Internal
# Returns: (no output)This was reported by an organization user with access to hundreds of private repositories via the GitHub UI, and independently confirmed with a personal GitHub account that also has private repositories.
What is expected
Get-GitHubRepository -Visibility Private should return all private repositories the authenticated user has access to. Get-GitHubRepository -Owner <org> -Visibility Private should return all private repositories in the organization the user can see.
Acceptance criteria
Get-GitHubRepository -Visibility Privatereturns all private repositories the authenticated user can accessGet-GitHubRepository -Owner <org> -Visibility Privatereturns all private org repositories the user can see- Pagination works correctly — all pages of results are returned, not just the first page
- No silent data loss when the result set exceeds one page
Environment
PSVersion: 7.5.4
GitHub module version: 0.40.4
Technical decisions
Root cause 1 — Pagination bug in Get-GitHubMyRepositories: The private function Get-GitHubMyRepositories (called when no -Owner is specified) has a pagination bug. At the end of the do...while loop, it references $response.pageInfo.hasNextPage and $response.pageInfo.endCursor, but $response is never defined — it should be $_.viewer.repositories.pageInfo.hasNextPage / .endCursor (matching the pattern used correctly in Get-GitHubRepositoryListByOwner). Because $response is $null, $hasNextPage is always falsy, causing the loop to exit after the first page. If the user has more repositories than $PerPage (default 100), the rest are silently dropped.
Root cause 2 — Default affiliation is too restrictive: Get-GitHubMyRepositories defaults the $Affiliation parameter to 'Owner'. This means Get-GitHubRepository -Visibility Private only returns private repositories the user owns — not repos from organizations (affiliation Organization_member) or collaborations (affiliation Collaborator). For the reported scenario (organization repos), the default excludes all org-owned private repos.
Fix for pagination: Replace $response.pageInfo with $_.viewer.repositories.pageInfo in Get-GitHubMyRepositories.ps1, matching the pattern already used in Get-GitHubRepositoryListByOwner.
Fix for affiliation: Consider changing the default $Affiliation to @('Owner', 'Organization_member', 'Collaborator') so that all accessible repositories are returned by default. Alternatively, keep the current default but document the behavior and let users opt in via -Affiliation. The former is more intuitive and matches user expectations.
Get-GitHubRepositoryListByOwner is correct: The org/user-specific path (Get-GitHubRepository -Owner <org>) uses correct pagination ($_.repositoryOwner.repositories.pageInfo) and passes Visibility correctly via GraphQL. No fix needed there.
Test approach: Integration tests listing private repos for the authenticated user, verifying count matches expectations. Pagination test with a low -PerPage to confirm all pages are fetched.
Implementation plan
Core fixes
- Fix pagination in
Get-GitHubMyRepositories.ps1— replace$response.pageInfo.hasNextPageand$response.pageInfo.endCursorwith$_.viewer.repositories.pageInfo.hasNextPageand$_.viewer.repositories.pageInfo.endCursor - Evaluate changing the default
$AffiliationinGet-GitHubMyRepositoriesfrom'Owner'to@('Owner', 'Organization_member', 'Collaborator')to return all accessible repos by default
Tests
- Add test verifying
Get-GitHubRepository -Visibility Privatereturns private repos - Add pagination test using a small
-PerPagevalue to confirm all pages are fetched - Add test verifying
Get-GitHubRepository -Owner <org> -Visibility Privatereturns org private repos
Metadata
Metadata
Assignees
Labels
Type
Projects
Status