Skip to content

How to list packages and versions in github package registry? #24680

How to list packages and versions in github package registry? #24680
Nov 21, 2019 · 8 answers

What is the best way to list github packages in a script?

Thanks,

Tom

fronix:

updatedAt

I found the following on the GraphQL API v4 change log page:

reg your updatedAt:

On member RegistryPackageVersion.updatedAt: updatedAt will be removed. 
Use the PackageVersion object instead. Effective 2020-04-01.

and on my registryPackages:

On member Organization.registryPackages: registryPackages will be removed.
Use the PackageOwner object instead. Effective 2020-04-01.

So I guess we are using some moving targets 😦
On the other hand, improving APIs is also good! :slight_smile:

Replies

8 suggested answers

…after a little bit of hacking I came up with the following bash script, using GraphQL/curl/jq:

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"){
registryPackages(name:"$g.$a",first:1) {
nodes {
versions(last:100) {
nodes {
version
}
}
}
}
}
}
EOF
)"
graphqlQuery "$query" | jq -r '.data.repository.registryPackages.nodes[0].versions.nodes[].version'
}

just thought I’d share it.

-Tom

0 replies

Since the registryPackages seems to have been refactored to packages I had to change my script around. Again, just thought I’d share it… her is my new version:

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(names:"$g.$a",first:1) {
nodes {
versions(first:100) {
nodes {
version
}
}
}
}
}
}
EOF
)"
graphqlQuery "$query" | jq -r '.data.repository.packages.nodes[0].versions.nodes[].version'
}

0 replies

Apparantly they removed the updatedAt aswell which is what I was using… Not sure how to get that date now can’t find anything.

Following does not work:

query {
          repository(owner: "User", name: "repo") {
              packages(first:100){
                nodes {
                    name,
                    packageType 
                    versions(first:100) {
                        nodes {
                            id,
                            version,
                            updatedAt
                        }
                    }
                }
              }
          }
      }
0 replies

So it seems the only way to get a date that should be something close to the actual package date would be PackageFile object.

New query:

query {
          repository(owner: "User", name: "repo") {
              packages(first:100){
                nodes {
                    id
                    name
                    packageType 
                    versions(first:100) {
                        nodes {
                            id
                            version
                            files(first: 10) {
                                nodes {
                                    name
                                    updatedAt
                                }
                            }
                        }
                    }
                }
              }
          }
      }
0 replies
fronix:

updatedAt

I found the following on the GraphQL API v4 change log page:

reg your updatedAt:

On member RegistryPackageVersion.updatedAt: updatedAt will be removed. 
Use the PackageVersion object instead. Effective 2020-04-01.

and on my registryPackages:

On member Organization.registryPackages: registryPackages will be removed.
Use the PackageOwner object instead. Effective 2020-04-01.

So I guess we are using some moving targets 😦
On the other hand, improving APIs is also good! :slight_smile:

0 replies
Answer selected

Yeah I found that as well, well seems like we’ll have to rewrite these things a few times before its out of beta 😛

0 replies

how can i run this on nodejs? i have no idea about GraphQl

0 replies

@SL-CodeBlaster - (late reply but for others who find this)

You can use the GitHub GraphQL Explorer: Explorer - GitHub Docs

Or you could use Postman:

  1. write a POST to https://api.github.com/graphql
  2. Add your GitHub PAT under the Authorization tab as a Bearer
  3. In the Body, change to GraphQL and copy in the query here

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants