Since @GabLeRoux pointed out that hub
now includes the ability to delete releases, and it has the ability to list drafts and format the output as we wish, I wrote the following to delete all draft releases from our repo:
hub release -f "%T (%S) %n" --include-drafts | grep " (draft)" | awk '{print $1}' | xargs -t -n1 hub release delete
Breaking this down:
hub release -f "%T (%S) %n" --include-drafts
: Prints all releases, and if they have a status like "draft" or "pre-release", put that status inside of parenthesis. You'll end up with output like this:
release-name-1 ()
release-name-2 ()
release-name-3 (draft)
release-name-4 ()
release-name-5 (draft)
release-name-6
Now pipe that into | grep " (draft)"
so that we only print lines with (draft)
:
release-name-3 (draft)
release-name-5 (draft)
Now for each of those lines, pipe that into | awk '{print $1}'
to take only the first part (before the first space). (This won't work if any releases have spaces in their name):
release-name-3
release-name-5
Now pipe all of those draft release names into xargs -t -n1 hub release delete
, which will call hub release delete <RELEASE_NAME_HERE>
for each line of input:
hub release delete release-name-3
hub release delete release-name-5
(As for those xargs params: -t
echoes the command first, and -n1
tells it to make a separate call to hub
for every line of input.)
If you want to go slow and see what draft releases it thinks it should delete, just run this portion:
hub release -f "%T (%S) %n" --include-drafts | grep " (draft)" | awk '{print $1}'
And if you want to go really slow, add -p
as a param to xargs, and it will prompt you before running each command.