Git

How to unstar all repository

date
Apr 11, 2023
slug
How to unstar all repository.
author
status
Public
tags
Github
summary
unstar repository automatically.
type
Post
thumbnail
category
Git
updatedAt
Apr 11, 2023 01:46 PM

How to unstar all repository.

 
 
  • Export variable
export APIKEY=xxxxxxxxx
  • Gain access to the starred repositories page.
curl -I -H "Authorization: token $APIKEY" <https://api.github.com/user/starred>
  • Retrieve the list of starred repositories and save it to a file called stars.txt.
for p in `seq 1 4`;do
echo page
curl -s -H "Authorization: token $APIKEY" <https://api.github.com/user/starred\\?page\\=$p> | jq -r '.[] |.full_name' >>stars.txt
done
  • Unstar any repositories that are listed in the stars.txt file.
while read REPO;do
echo
curl -X DELETE -s -H "Authorization: token $APIKEY" <https://api.github.com/user/starred/$REPO>
sleep .5
done<stars.txt
 
Shell Script

#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

STARS_PAGE_COUNT=20
STARS_FILE=stars.txt
DELETE_SLEEP_TIME=.5

function get_all_star_repos() {
  for p in $(seq 1 $STARS_PAGE_COUNT);do
    echo "page: $p"
    curl -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred\?page\=$p | jq -r '.[] |.full_name' >> $STARS_FILE
  done
}

function remove_all_star_repos() {
  while read REPO;do
    echo "REPO: $REPO"
    curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/$REPO
    sleep $DELETE_SLEEP_TIME
  done < $STARS_FILE
}

get_all_star_repos
remove_all_star_repos