Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active March 31, 2024 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/3fc9c9083be3f5e8dad4f77d7cafeda6 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/3fc9c9083be3f5e8dad4f77d7cafeda6 to your computer and use it in GitHub Desktop.
Gets a list of repositories of a GitHub user
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))
}
@AfroThundr3007730
Copy link
Author

Updated version available in my HelperFunctions module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment