Skip to main content
Data Science Wizardry Blog by Attila Vajda

Deleting repositories and practicing one liners.

{
  "message": "Bad credentials",
  "documentation_url": "https://docs.github.com/rest"
}

I am trying to automate the deletion of unused repositories from my GitHub account.

I misspelled the token.

What is the meaning of curl in bash?

We can look up the description in the user manual:

man curl

Asking only one liners from the computer agent seems like a good idea, because this would help familiarisation with one liners. Asking only one liners from the computer agent seems like a good idea, but the one liners can be made into puzzles as well. Asking only one liners from the computer agents seems like a good idea, so I try this idea.

How to delete every repository but one:

gh repo list -L 1000 | grep -v "some_repository_name" | cut -f 1 | xargs -I {} gh repo delete {} --confirm
token="YOUR_TOKEN"; repo_to_keep="some_repository_name"; repos=$(curl -H "Authorization: token $token" https://api.github.com/user/repos?type=all | jq -r '.[].name'); for repo in $repos; do [ "$repo" != "$repo_to_keep" ] && curl -X DELETE -H "Authorization: token $token" "https://api.github.com/repos/user/$repo"; done
gh repo list -L 1000 | awk '!/some_repository_name/ {print $1} ' | xargs -I {} gh repo delete {} --yes

This third line seems concise enough for our purposes.

gh repo list -L 1000 | awk '!/some_repository_name/ {print $1}'

results in a list that contains 'some_repository_name', but this directory should be excluded.

gh repo list -L 1000 | grep -v "some_repository_name" | awk {print $1}

Oh, the awk exclusion did actually work, but I wrote some_repository_name instead of some-repository-name.