Ecosystem Community Update October, 2021

Hey all :wave:

Here to provide some updates in this space. Hoping to keep these coming in the future, but here’s our first!

Did you Know?

Tags and Releases are unique, and not the same thing?

Fetching the list of releases for a repository that only has tags, will return an empty array because the repository doesn’t have any releases – it will only have tags. github.com lists both GitHub Releases and Git Tags on the same Releases page, but those two features are separate in the API and the API has separate endpoints for listing tags and releases.

You can get the list of tags via this endpoint:

You can get the list of releases via this endpoint:

Work It Out!

Users often want to know how many items there are in a list of resources (e.g. how many repositories a user starred). However, the REST API doesn’t return such a count and just returns a paginated list of resources. Fetching the complete list would allow users to count all resources in the list, but that would require making lots of API calls which would be expensive.

There’s a neat trick which allows determining the total count with a single REST API request, using the Link pagination header.

First, if you want to continue with the REST API, you can use this method to avoid fetching all pages. If you set the per_page pagination parameter to 1, then each page will contain 1 item. As a result, the number of pages will also tell you the total number of items. And you can get the number of pages from the URL for the last page in the Link header:

So, with just one request – you can get the total number of items.

Here’s an example using curl for fetching the number of releases in the atom/atom repository:

curl -I https://api.github.com/repos/atom/atom/releases?per_page=1

...
link: <https://api.github.com/repositories/3228505/releases?per_page=1&page=2>; rel="next", <https://api.github.com/repositories/3228505/releases?per_page=1&page=534>; rel="last"

Notice that the Link header has this rel="last" URL:

https://api.github.com/repositories/3228505/releases?per_page=1&page=534

This tells you that there are 534 pages of results, and because there is one item per page – the total number of releases is 534.

The second workaround is to use the GraphQL API:

The GraphQL API is a different approach for programmatic access from the REST API, and among other things allows you to fetch the total count for any connection.

For example, the Repository object has a releases connection:

And that connection has a totalCount value which gives you the total number of releases:

Here’s an example GraphQL query for fetching the number of releases in the atom/atom repository:

{
  repository(name: "atom", owner: "atom") {
    releases {
      totalCount
    }
  }
}

and if you run that in the GraphQL Explorer (Explorer - GitHub Docs) you will get the same result (534):

{
  "data": {
    "repository": {
      "releases": {
        "totalCount": 534
      }
    }
  }
}

Hot Off the Press

Of course, we can find status details for upcoming features on Our Public Roadmap, but for our Enterprise users, Audit Log Streaming is now available and in-beta:

Audit log streaming is now in public beta | The GitHub Blog :tada:

Hubbers at Work :construction:

Notebooks in GitHub have had some troubles, in the recent past. Our two most notible threads are:

…and I have good news!

Recently, we have founded a new team who will be handling the services that render out notebooks in our UI, and we have resolved to push some big improvements by the end of 2021. Stand by, you data scientists, for an improved experience, soon.


Until next time, be well :heart:

3 Likes