Allow fetching the tarball URL for a Commit or Ref

schema-request

#1

We are using the API currently to get the tarball URL and download the artifact to deploy our apps.
It would be rad to be able to get that from the GraphQL API.


#2

Thank you for the schema request, @ys1. That certainly seems doable.

I’ve added this request to our internal tracker and will update you here when we have more information to share.


#3

Hey @ys1, we’ve just shipped the ability to fetch tarball and zipball URLs via the GraphQL API :slight_smile:

https://developer.github.com/v4/reference/object/commit/#fields

Thanks for the feature request!


#4

Can you add this to repository? Or at least tag so its easy to fetch?

PSA:

An example of how to do this

{
  repository(owner: "k0shk0sh", name: "FastHub") {
    ref(qualifiedName: "refs/heads/master") {
      target {
        ... on Commit {
          history(first: 1) {
            edges {
              node {
                zipballUrl 
              }
            }
          }
        }
      }
    }
  }
}

#5

@ys1

Since we’re really grabbing the zip of the repository at a certain commit, putting the ziballUrl on the repository object wouldn’t really make sense without specifying a commit. From Repository, we can grab the master commit zipball like this:

query {
  repository(owner: "foo", name: "bar") {
    defaultBranchRef {
      target {
        ... on Commit {
          zipballUrl
        }
      }
    }
  }
}

Will this work for you?


#6

This is great! Can you add by tag?


#7

From a Tag,

tag{
  target{
    ... on Commit{
      zipballUrl
    }
  }
}

Will this work?


#8

Thanks a lot @d12 I will look into this and hopefully bring it to our tools:slight_smile:


#9

That looks good. Default branch tag possible?


#10

Not presently. If defaultBranchRef doesn’t offer what you need, feel free to open another feature request!


#11

OK np was just asking. Thanks for all your work! We will be using this shortly.


#12

If you have curl and jq installed, then you can grab the url for the latest tarball off the master branch as follows.

... adapt :token, :org, :repo, :branch, :tag as required

# grab the tip commit on the default branch
curl -sHAuthorization:Bearer\ :token \
  -XPOST https://api.github.com/graphql \
  -d '{"query":"{repository(owner: \":org\", name: \":repo\") { defaultBranchRef { target { ... on Commit {tarballUrl}}}}}"}' \
  | jq '.data.repository.defaultBranchRef.target.tarballUrl'

# grab a specific :tag
curl -sHAuthorization:Bearer\ :token \
  -XPOST https://api.github.com/graphql \
  -d '{"query":"{repository(owner: \":org\", name: \":repo\") {ref(qualifiedName: \"refs/tags/:tag\") {target{... on Commit{tarballUrl}}}}}"}' \
  | jq '.data.repository.ref.target.tarballUrl'

# grab the tip commit off a specific :branch
curl -sHAuthorization:Bearer\ :token \
  -XPOST https://api.github.com/graphql \
  -d '{"query":"{repository(owner: \":org\", name: \":repo\") {ref(qualifiedName: \"refs/heads/:branch\") {target {... on Commit { history(first: 1) {edges {node {tarballUrl}}}}}}}}}"}' \
  | jq '.data.repository.ref.target.history.edges[].node.tarballUrl'

#13

Can I get the “greatest” tag (assuming semver & sortability of versioned tags) cleanly? e.g. a project has tagged, in time order:

[v1.1, v2.0, v2.1, v1.2] -> should give me v2.1 as the greatest version even though 1.2 was released later in time. This is a classic use case for projects that have a stable & development branch/tag structure.

Also, is it possible to get graphql to return only the final leaf node somehow? This would allow a shell or user script to only need curl or similar http agent to get the required URL in a single clean invocation.


#14

Hey @dch,

There isn’t a way to sort tags by semver. The ALPHABETICAL sort field may work for your use case, but smart ordering by semver isn’t something we’re planning on implementing right now.

On your second question, there isn’t a way to query for a leaf without any JSON structure, as that would violate the GraphQL spec. If you think it might help, you could label your leaf with a searchable name!

query{
  repository(owner: "d12", name: "test"){
    AAA: nameWithOwner
  }
}
{
  "data": {
    "repository": {
      "AAA": "d12/test"
    }
  }
}