Last active
October 4, 2024 21:39
-
-
Save AfroThundr3007730/3fc9c9083be3f5e8dad4f77d7cafeda6 to your computer and use it in GitHub Desktop.
Gets a list of repositories of a GitHub user
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
Set-StrictMode -Version Latest | |
function Get-GHRepoList { | |
<# .SYNOPSIS | |
Gets a list of repositories of a GitHub user. #> | |
Param( | |
# User to enumerate | |
[string]$User, | |
# Page size to request | |
[int]$Size = 100 | |
) | |
$page = 0 | |
$count = (Invoke-RestMethod -Uri ('https://api.github.com/users/{0:s}' -f $User)).public_repos | |
Write-Verbose ('Total repos for user {0:s} is {1:d}.' -f $User, $count) | |
do { | |
$page++ | |
Write-Verbose ('Retrieving page {0:d} of {1:d} results.' -f $page, $Size) | |
(Invoke-RestMethod -Uri ('https://api.github.com/users/{0:s}/repos?page={1:d}&per_page={2:d}' -f $User, $page, $Size)).html_url | |
Start-Sleep -Seconds 1 | |
} while ($page * $size -lt $count) | |
Write-Verbose ('Stopped at batch size {0:d}' -f ($page * $size)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version available in my HelperFunctions module.