Skip to content

Instantly share code, notes, and snippets.

@joshjohanning
Last active January 7, 2022 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshjohanning/dd01c4543c92b3567eaa2ce1d381825f to your computer and use it in GitHub Desktop.
Save joshjohanning/dd01c4543c92b3567eaa2ce1d381825f to your computer and use it in GitHub Desktop.
Get package version download url for a specific package and specific version
{
repository(owner: "joshjohanning", name: "Wolfringo-github-packages") {
packages(first: 10, packageType: NUGET, names: "Wolfringo.Commands") {
edges {
node {
id
name
packageType
version(version: "1.1.2") {
id
version
files(first: 10) {
nodes {
name
updatedAt
size
url
}
}
}
}
}
}
}
}
@joshjohanning
Copy link
Author

joshjohanning commented Nov 30, 2021

(apologies I am a graphql noob)

this returns something like

{
  "data": {
    "repository": {
      "packages": {
        "edges": [
          {
            "node": {
              "id": "MDc6UGFja2FnZTYzNjAxOA==",
              "name": "Wolfringo.Commands",
              "packageType": "NUGET",
              "version": {
                "id": "MDE0OlBhY2thZ2VWZXJzaW9uNzE5MjAwMA==",
                "version": "1.1.2",
                "files": {
                  "nodes": [
                    {
                      "name": "package.nupkg",
                      "updatedAt": "2021-02-23T18:38:50Z",
                      "size": 95064,
                      "url": "https://github-registry-files.githubusercontent.com/341640418/5e5d8280-7606-11eb-974a-d1d68831b6e1?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211130%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211130T200744Z&X-Amz-Expires=300&X-Amz-Signature=0c3cabb7c8be7b603d69247743d22695e432a127115d11bdca4240c3efd93643&X-Amz-SignedHeaders=host&actor_id=19912012&key_id=0&repo_id=341640418&response-content-disposition=filename%3Dpackage.nupkg&response-content-type=application%2Foctet-stream"
                    }
                  ]
                }
              }
            }
          }
        ]
      }
    }
  }
}

@joshjohanning
Copy link
Author

It's slightly less gross if you just need to the latest package version download url

{
  repository(owner: "joshjohanning", name: "Wolfringo-github-packages") {
    packages(first: 10, packageType: NUGET, names: "Wolfringo.Commands") {
      edges {
        node {
          id
          name
          packageType
          versions(first: 100) {
            nodes {
              id
              version
              files(first: 10) {
                nodes {
                  name
                  url
                }
              }
            }
          }
        }
      }
    }
  }
}

Result:

{
  "data": {
    "repository": {
      "packages": {
        "edges": [
          {
            "node": {
              "id": "MDc6UGFja2FnZTYzNjAxOA==",
              "name": "Wolfringo.Commands",
              "packageType": "NUGET",
              "versions": {
                "nodes": [
                  {
                    "id": "MDE0OlBhY2thZ2VWZXJzaW9uNzE5MjAwMA==",
                    "version": "1.1.2",
                    "files": {
                      "nodes": [
                        {
                          "name": "package.nupkg",
                          "url": "https://github-registry-files.githubusercontent.com/341640418/5e5d8280-7606-11eb-974a-d1d68831b6e1?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211130%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211130T194734Z&X-Amz-Expires=300&X-Amz-Signature=4fbb0baf3d692cb706507b6f24b91705e6a7f6fc7a8c38a128b37111bff8487e&X-Amz-SignedHeaders=host&actor_id=19912012&key_id=0&repo_id=341640418&response-content-disposition=filename%3Dpackage.nupkg&response-content-type=application%2Foctet-stream"
                        }
                      ]
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}

@joshjohanning
Copy link
Author

joshjohanning commented Jan 7, 2022

Example of using curl command to get the latest download url(s):

curl 'https://api.github.com/graphql' \
  -s \
  -X POST \
  -H 'content-type: application/json' \
  -H "Authorization: Bearer xxx" \
  --data '{"query":"{\n  repository(owner: \"joshjohanning-org\", name: \"Wolfringo-github-packages\") {\n    packages(first: 10, packageType: NUGET, names: \"Wolfringo.Commands\") {\n      edges {\n        node {\n          id\n          name\n          packageType\n          versions(first: 100) {\n            nodes {\n              id\n              version\n              files(first: 10) {\n                nodes {\n                  name\n                  url\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}","variables":{}}' \
  | jq -r '.data.repository.packages.edges[].node.versions.nodes[].files.nodes[].url'
  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment