Skip to content

Commit ffaa897

Browse files
Update ExportGitHubUsageStatsForOrganization.ps1
Added code to check if repo API URLs are valid, and if not, to remove them from the list of repos. This was causing an issue with repos that were recently deleted, or internal repos when permissions for the API account are not setup correctly to read private repo info.
1 parent bc15bc5 commit ffaa897

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

PowerShell-Scripts/ExportGitHubUsageStatsForOrganization.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,22 @@ Write-Host "Getting repos..."
4848
$repoCount = [int]0
4949
try
5050
{
51+
# Get repos
5152
$repos = Get-GitHubRepository -OrganizationName $organizationName
53+
54+
# Filter out deleted repos
55+
$repos = $repos | Where-Object {
56+
try {
57+
$null = Invoke-RestMethod -Uri $_.url -Method Get
58+
$true
59+
} catch {
60+
$false
61+
}
62+
}
63+
64+
# Save count of valid repos found
5265
$repoCount = [int]$repos.Count
66+
5367
} catch {
5468
Write-Host -f Red "Error while getting repository information. Ensure the organization and credentials are correct."
5569
}

0 commit comments

Comments
 (0)