Created
September 25, 2025 23:16
-
-
Save stevencohn/2b35213373676fdff7951595581f2a26 to your computer and use it in GitHub Desktop.
Get top commenters for all issues in specified repo
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
[CmdletBinding(SupportsShouldProcess = $true)] | |
param( | |
[string] $owner = $env:GITHUB_USER, | |
[string] $token = $env:GITHUB_TOKEN, | |
[string] $repo = 'OneMore', | |
[string] $since = "$((Get-Date).Year)-01-01" | |
) | |
Begin | |
{ | |
$url = "https://api.github.com/repos/$owner/$repo/issues/comments?since=$since&page=0&per_page=500" | |
$headers = @{ | |
Authorization = "Bearer $token" | |
Accept = "application/vnd.github+json" | |
} | |
} | |
process | |
{ | |
Write-Host "... fetching issue comments from $owner/$repo" | |
$users = @{} | |
do { | |
$response = Invoke-WebRequest -Uri $url -Headers $headers | |
$comments = $response.Content | ConvertFrom-Json | |
foreach ($comment in $comments) | |
{ | |
$user = $comment.user.login | |
if ($users.ContainsKey($user)) { | |
$users[$user]++ | |
} else { | |
$users[$user] = 1 | |
} | |
} | |
# Parse Link header for next page | |
$linkHeader = $response.Headers["Link"] | |
$nextUrl = $null | |
if ($linkHeader) | |
{ | |
$matches = [regex]::Matches($linkHeader, '<([^>]+)>;\s*rel="next"') | |
if ($matches.Count -gt 0) | |
{ | |
$nextUrl = $matches[0].Groups[1].Value | |
Write-Host "... next $nextUrl" -fore DarkGray | |
} | |
} | |
$url = $nextUrl | |
} while ($url) | |
# sort and display top commenters | |
$users.GetEnumerator() | sort -Property Value -Descending | select -First 20 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment