Last active
April 28, 2020 10:44
-
-
Save hostmaster/16585823239f2a518a90c5d1e7663379 to your computer and use it in GitHub Desktop.
get a list package versions in GitHub Package Repository
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 | |
set -eo pipefail | |
TOKEN=${GITHUB_TOKEN:?environment variable is empty or unset} | |
[ -n "$1" ] && GITHUB_REPOSITORY=$1 | |
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:? please provide a name of a repository} | |
OWNER=$(echo $GITHUB_REPOSITORY | cut -d/ -f1) | |
REPO=$(echo $GITHUB_REPOSITORY | cut -d/ -f2-) | |
jq -cn ' | |
{ | |
query: $query, | |
variables: { | |
owner: $owner, | |
repo: $repo | |
} | |
}' \ | |
--arg query ' | |
query ($owner: String!, $repo: String!, ) { | |
repositoryOwner(login: $owner) { | |
repository(name: $repo) { | |
registryPackagesForQuery(packageType: DOCKER, last:10) { | |
nodes { | |
versions(last: 100) { | |
nodes { | |
version | |
} | |
} | |
} | |
} | |
} | |
} | |
}' \ | |
--arg owner "$OWNER" \ | |
--arg repo "$REPO" | | |
curl -s -H "Authorization: bearer $TOKEN" -X POST \ | |
-d @- https://api.github.com/graphql | | |
jq -r '.data.repositoryOwner.repository.registryPackagesForQuery.nodes|.[]|.versions.nodes|.[]|.version' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment