Last active
March 2, 2020 08:51
-
-
Save sodonnell/d9d38582fd1df5698c31c1068910ee90 to your computer and use it in GitHub Desktop.
Safely cleaning-up crusty github forks from your repository list using bash...
This file contains 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
#!/usr/bin/env bash | |
# | |
# This script is intended to interactively help you remove stale/unwanted github forks | |
# from your repo list, without accidently removing any of your actual (non-forked) repos. | |
# | |
# The use case for this is simple: I forked wayyyy too many repos that I should | |
# have otherwise 'starred', and wanted to clean-up my repository list. | |
# | |
# Manually purging all of my forked github repos via the github.com webui would take | |
# far too much effort, so I decided to automate the majority of the process. | |
# | |
# I didn't want to remove all of my forked repos, and I didn't want to remove | |
# ANY of my personal repos, so I made this interactive script to help me | |
# SAFELY dictate which forked repos that I did want purged. | |
# | |
# Author: Sean O'Donnell - https://github.com/sodonnell | |
# | |
API_TOKEN="Add your github Token here" | |
API_URL=https://api.github.com | |
function scrape_forks() | |
{ | |
curl -s GET "${API_URL}/user/repos" -H "Authorization: Bearer ${API_TOKEN}" | jq -r '.[] | select(.fork) | .full_name' | |
} | |
function delete_repo() | |
{ | |
curl -X DELETE "${API_URL}/repos/${fork}" -H "Authorization: Bearer ${API_TOKEN}" | |
} | |
forks=`scrape_forks` | |
if [ -z $forks ]; then | |
echo "No forked repos found." | |
else | |
for fork in ${forks}; do | |
echo -e "[Warning] Permanently remove repo: ${fork} (Y/N)?" | |
read CONFIRM | |
if [ $CONFIRM == "Y" ]; then | |
delete_repo | |
echo -e "Deleted: ${fork}\n" | |
else | |
echo -e "Ignored: ${fork}\n" | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment