Why does the API sometimes return year old tags instead of the most recent ones? Can you override the default sorting?

How can you make sure that you get the same tag sorting from the API as they are displayed on the tags page?

Some repos, like MariaDB/server, return year old tags, and I can’t figure out how to get the latest ones.

If you run curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/mariadb/server/tags, you get back tokumx-1.4.0+hotfix.0 first, while mariadb-10.6.0 is the most recent tag here.

Hey there @sfkpmr :wave:

Thanks for joining us here in the Community and for bringing up this behavior. I had to scour a bit to find out if there has been any update to this behavior, but it seems that, no.

Currently, listing all tags from a repo will return in reverse alphabetical order. Yikes…

We do have one open issue internally, but there’s little to no traction on it. It could be because you can workaround this by using the v4 GraphQL API as mentioned in this SO thread:

The answer there is essentially what would solve for your use case.

Going forward though, it would be absolutely amazing if you could submit this suggestion via our feedback form:

…which will get eyes on by our PM teams for consideration.

I’m also going to bump our internal FR with this thread.

In the meantime would that GraphQL solution work for you, or are you hoping to limit your usage to REST?

Hey, thanks for the answer!

That would explain it! Curious why this behaviour only shows up for certain repos though? curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/nginx/nginx/tags shows the same result as the nginx tags page.

I’d prefer REST as I have no experience with GraphQL, but might have to take a look at it in the meantime.

Does it, for you?

When I run the curl against nginx/nginx, I get:

 curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/mariadb/server/tags
    "name": "tokumx-1.4.0+hotfix.0",
    "zipball_url": "https://api.github.com/repos/MariaDB/server/zipball/refs/tags/tokumx-1.4.0+hotfix.0",
    "tarball_url": "https://api.github.com/repos/MariaDB/server/tarball/refs/tags/tokumx-1.4.0+hotfix.0",
    "commit": {
      "sha": "dfcffcc714ee5f848c7c3aa522b6bb464678e737",
      "url": "https://api.github.com/repos/MariaDB/server/commits/dfcffcc714ee5f848c7c3aa522b6bb464678e737"
    "node_id": "MDM6UmVmMTk4MTYwNzA6cmVmcy90YWdzL3Rva3VteC0xLjQuMCtob3RmaXguMA=="

And their release tags, show: release-1.20.0 as the first returned.

Do you see unique behavior?

I think you curl’d mariadb/server :slight_smile:

Indeed, it returns this for me:

[sfkpmr@vm ~]# curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/nginx/nginx/tags                                                                                                                                [
    "name": "release-1.20.0",
    "zipball_url": "https://api.github.com/repos/nginx/nginx/zipball/refs/tags/release-1.20.0",
    "tarball_url": "https://api.github.com/repos/nginx/nginx/tarball/refs/tags/release-1.20.0",
    "commit": {
      "sha": "affbe0b8e14a3ce17d1a40f0fa4518d1309a917d",
      "url": "https://api.github.com/repos/nginx/nginx/commits/affbe0b8e14a3ce17d1a40f0fa4518d1309a917d"
    "node_id": "MDM6UmVmMzc5MTIzOTg6cmVmcy90YWdzL3JlbGVhc2UtMS4yMC4w"
    "name": "release-1.19.10",
    "zipball_url": "https://api.github.com/repos/nginx/nginx/zipball/refs/tags/release-1.19.10",
    "tarball_url": "https://api.github.com/repos/nginx/nginx/tarball/refs/tags/release-1.19.10",
    "commit": {
      "sha": "95d97aedb982b4195a002eadf1d4360bbc10f8d7",
      "url": "https://api.github.com/repos/nginx/nginx/commits/95d97aedb982b4195a002eadf1d4360bbc10f8d7"
    "node_id": "MDM6UmVmMzc5MTIzOTg6cmVmcy90YWdzL3JlbGVhc2UtMS4xOS4xMA=="
    "name": "release-1.19.9",
    "zipball_url": "https://api.github.com/repos/nginx/nginx/zipball/refs/tags/release-1.19.9",
    "tarball_url": "https://api.github.com/repos/nginx/nginx/tarball/refs/tags/release-1.19.9",
    "commit": {
      "sha": "9148be81739917dcf19d08ccf955b2fd8fc7709b",
      "url": "https://api.github.com/repos/nginx/nginx/commits/9148be81739917dcf19d08ccf955b2fd8fc7709b"
    "node_id": "MDM6UmVmMzc5MTIzOTg6cmVmcy90YWdzL3JlbGVhc2UtMS4xOS45"

Oops!! I did, indeed… that’s my bad!

Let me get back to this and see why nginx seems to not follow the same sorting we expect.

I actually have a list of repos that do and don’t sort properly.

Those that seem to return the same order as the tags page: apache/httpd, openvpn/openvpn, perl/perl5, git/git, django/django.

And those that don’t: mariadb/server, golang/go, owncloud/core, mongodb/mongo, splitbrain/dokuwiki.

1 Like

Hey again @sfkpmr :wave:

Okay so the reverse alphabetical sorting is still the expected behavior. Though why we see different looking results from different repositories, is primarily related to the tag/release syntax used in those repos.

As tag/release notation changes over time, it will seemingly not match that expected reverse alphabetical sorting from the API.

To reiterate, we do have an internal issue that I’ve added this thread to. We do also recommend submitting your preference via our feedback form. And lastly, GraphQL should allow you to choose sorting methods that suit your use case.

If there’s still something that doesn’t seem “right,” let’s focus on something specific and we can dig deeper.