Skip to content

Instantly share code, notes, and snippets.

@nickadam
Created July 18, 2023 16:11
Show Gist options
  • Save nickadam/092f5291c7508486b9093fe1b86e645d to your computer and use it in GitHub Desktop.
Save nickadam/092f5291c7508486b9093fe1b86e645d to your computer and use it in GitHub Desktop.
List Org Repos and Contributors
$org = "Your Org"
$api_key = "Your PAT"
function Get-GitHubApi(){
param($Url)
$Headers = @{Authorization = "Bearer $api_key"}
$wr = Invoke-WebRequest -UseBasicParsing -Headers $Headers $Url
$wr.Content | ConvertFrom-Json -Depth 100
if([string]($wr.Headers.link -split "," -match 'rel="next"') -match "https[^>]+"){
Get-GitHubApi $matches[0]
}
}
$repos = Get-GitHubApi "https://api.github.com/orgs/$org/repos"
$repos | ForEach-Object {
$full_name = $_.full_name
$html_url = $_.html_url
$contributors = Get-GitHubApi "https://api.github.com/repos/$full_name/contributors"
$contributors_list = $contributors.login -join ', '
[PSCustomObject]@{
Url = $html_url
Contributors = $contributors_list
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment