Skip to content

Instantly share code, notes, and snippets.

@mika76
Forked from sebble/stars.sh
Last active January 28, 2024 15:08
Show Gist options
  • Save mika76/2dd7be2e982c7b12fc88445d8064fc4d to your computer and use it in GitHub Desktop.
Save mika76/2dd7be2e982c7b12fc88445d8064fc4d to your computer and use it in GitHub Desktop.
List all starred repositories of a GitHub user.
[CmdletBinding()]
param (
[Parameter()]
[string]
$user = "mika76"
)
$URL = "https://api.github.com/users/$user/starred"
$PAGE = 0
# $totalStars = (Invoke-WebRequest "$($URL)?per_page=1").RelationLink.last
# | Select-String -Pattern "&page=(?<p>\d+)" -AllMatches
# | % { $_.Matches }
# | % { $_.Groups }
# | Where-Object { $_.Name -eq "p"}
# | % { $_.Value }
do {
$PAGE++
$r = Invoke-WebRequest -Uri "$($URL)?per_page=500&page=$($PAGE)" -Headers @{'Accept' = 'application/vnd.github.v3.star+json' }
$isLastPage = -not $r.RelationLink.ContainsKey("last")
$r.Content | ConvertFrom-Json | Select-Object starred_at, @{n = 'full_name'; e = { $_.repo.full_name } }
} until ($isLastPage)
#!/bin/bash
USER=${1:-mika76}
STARS=$(curl -sI https://api.github.com/users/$USER/starred?per_page=1|egrep '^link'|egrep -o 'page=[0-9]+'|tail -1|cut -c6-)
PAGES=$(($STARS/100+1))
echo You have $STARS starred repositories.
echo
for PAGE in `seq $PAGES`; do
curl -sH "Accept: application/vnd.github.v3.star+json" "https://api.github.com/users/$USER/starred?per_page=100&page=$PAGE"|jq -r '.[]|[.starred_at,.repo.full_name]|@tsv'
done
echo
# curl -sI https://api.github.com/users/$USER/starred?per_page=100|egrep '^Link: '|tr , \\n|grep 'rel="next"'|egrep -o '<https[^>]+'|tr -d \<
@scollovati
Copy link

If I run the Bash version I get:

arithmetic expression: expecting primary: "/100+1"

@mika76
Copy link
Author

mika76 commented Apr 14, 2020

Fixed - looks like "link" used to start with a capital letter...

@mika76
Copy link
Author

mika76 commented Aug 17, 2021

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