Skip to content

Instantly share code, notes, and snippets.

@sebble
Last active October 8, 2024 16:00
Show Gist options
  • Save sebble/e5af3d03700bfd31c62054488bfe8d4f to your computer and use it in GitHub Desktop.
Save sebble/e5af3d03700bfd31c62054488bfe8d4f to your computer and use it in GitHub Desktop.
List all starred repositories of a GitHub user.
#!/bin/bash
USER=${1:-sebble}
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=$((658/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 \<
@sebble
Copy link
Author

sebble commented Jan 29, 2017

Should really use the "Link" headers for pagination.

@mika76
Copy link

mika76 commented Oct 18, 2019

This is pretty useful - thanks!

@richrd
Copy link

richrd commented Mar 13, 2020

Thanks, this was way nicer than trying to go through the paginated list on GitHub. 👍

@mika76
Copy link

mika76 commented Mar 24, 2020

I think you have a bug with the number 658 that should be $STARS no?

Also I've converted this to powershell for any Windows people who might need it: https://gist.github.com/mika76/2dd7be2e982c7b12fc88445d8064fc4d#file-stars-ps1

Thanks again @sebble - it's really useful!

@scollovati
Copy link

scollovati commented Apr 14, 2020

What about writing it to a csv file with also the direct link to the repository?

Furthermore, at least for my user, this line seems not to work:

STARS=$(curl -sI https://api.github.com/users/$USER/starred?per_page=1|egrep '^Link'|egrep -o 'page=[0-9]+'|tail -1|cut -c6-)

@alik604
Copy link

alik604 commented Sep 2, 2020

I wrote this, it will open all starred GitHub repositories in new tab.

The life of a windows user :'(

@juergenhoetzel
Copy link

I came up with this simple shell script leveraging jq:

user=juergenhoetzel
while curl -s "https://api.github.com/users/$user/starred?per_page=100&page=${page:-1}" \
		    |jq -r -e '.[].full_name' && [[ ${PIPESTATUS[1]} != 4 ]]; do
    let page++
done

https://gist.github.com/juergenhoetzel/e8dc1d66de92717d49c60a2dafced725

@juergenhoetzel
Copy link

Powershell script using build-in JSON parsing:

$user = "juergenhoetzel"
$p = 1
do  {
    $full_names = Invoke-RestMethod "https://api.github.com/users/$user/starred?per_page=100&page=$p"
    $full_names.ForEach({$_.full_name})
    $p++
} while ($full_names.Length -gt 0)

https://gist.github.com/juergenhoetzel/1a0a73766a93942ed24722587f821edf

@niyazFattahov
Copy link

doesnt work
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"
jq: error (at :4): Cannot index string with string "starred_at"

@meganerd
Copy link

meganerd commented Oct 3, 2022

doesnt work jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at"

You are running into non-authenticated api rate limiting. Generate a token:
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

The easiest way to use this token is to set it to the environment variable GITHUB_TOKEN.

@cs-mshah
Copy link

cs-mshah commented Oct 21, 2022

doesnt work jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at" jq: error (at :4): Cannot index string with string "starred_at"

You need to do:
sudo apt-get install -y jq and have a GITHUB_TOKEN

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