Last active
November 19, 2020 06:31
-
-
Save girishaiocdawacs/36171d539e2a76bb7fad7f1c985553ba to your computer and use it in GitHub Desktop.
github package maintenance
This file contains hidden or 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
#!/bin/bash | |
# | |
# .d8b. db d8b db .d8b. .o88b. .d8888. .o88b. db .d88b. db db d8888b. | |
# d8' `8b 88 I8I 88 d8' `8b d8P Y8 88' YP d8P Y8 88 .8P Y8. 88 88 88 `8D | |
# 88ooo88 88 I8I 88 88ooo88 8P `8bo. 8P 88 88 88 88 88 88 88 | |
# 88~~~88 Y8 I8I 88 88~~~88 8b `Y8b. 8b 88 88 88 88 88 88 88 | |
# 88 88 `8b d8'8b d8' 88 88 Y8b d8 db 8D Y8b d8 88booo. `8b d8' 88b d88 88 .8D | |
# YP YP `8b8' `8d8' YP YP `Y88P' `8888Y' `Y88P' Y88888P `Y88P' ~Y8888P' Y8888D' | |
# | |
# Copyright 2021 | |
INPUT_TOKEN=<Your github token> | |
USERNAME="your github username" | |
# change visibility to private for repo as public package can not be removed just like that. | |
REPOSNAME="awacs-cloud-commons" | |
graphqlQuery() { | |
local query="$1"; shift | |
curl -s -H "Authorization: bearer $INPUT_TOKEN" -X POST -d '{"query":"'"$query"'"}' 'https://api.github.com/graphql' | |
} | |
listPackageVersions() { | |
local g="$1"; shift | |
local a="$1"; shift | |
local query="$(cat <<EOF | sed 's/"/\\"/g' | tr '\n\r' ' ' | |
query { | |
repository(owner: "$USERNAME", name: "$REPOSNAME") { | |
packages(first:100){ | |
nodes { | |
id | |
name | |
packageType | |
versions(first:100) { | |
nodes { | |
id | |
version | |
files(first: 10) { | |
nodes { | |
name | |
updatedAt | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
EOF | |
)" | |
graphqlQuery "$query" | |
} | |
listPackageVersions | |
# usage ./gh.sh | jq -r .data.repository.packages.nodes[].versions.nodes[].id | |
This file contains hidden or 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
Usage | |
./gh.sh | jq -r .data.repository.packages.nodes[].versions.nodes[].id | |
MDIyOlJlZ2lzdHJ5UGFja2FnZVZlcnNpb243MTExNg== | |
curl -X POST \ | |
-H "Accept: application/vnd.github.package-deletes-preview+json" \ | |
-H "Authorization: bearer $GITHUB_TOKEN" \ | |
-d '{"query":"mutation { deletePackageVersion(input:{packageVersionId:\"MDIyOlJlZ2lzdHJ5UGFja2FnZVZlcnNpb243MTExNg==\"}) { success }}"}' \ | |
https://api.github.com/graphql | |
{"data":{"deletePackageVersion":{"success":true}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment