Ordering of tags


#1

I recently saw that the order of tags is weird. Take for example the erlang/otp repository.

When I query all tags (after “OTk=”) using this query:

query {
  repository(owner: "erlang", name: "otp") {
    tags: refs(refPrefix: "refs/tags/", first: 10, after: "OTk=", direction: ASC) {
      edges {
        cursor
        node {
          id
          name
          target {
            ... on Tag {
              id
              author:tagger {
                name
                date
              }
            }
						... on Commit {
              id
              author:committer {
                name
                date
              }
            }
          }
        }
      }
      pageInfo {
       endCursor
       hasNextPage
       hasPreviousPage
       startCursor
      }
    }
  }
}

I get a weird ordering:

{
  "data": {
    "repository": {
      "tags": {
        "edges": [
          {
            "cursor": "MTAw",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUC0yMC4wLjU=",
              "name": "OTP-20.0.5",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjMxMDBkOTNmMDM1MmFjYWMzMGU1ODMwOWM4MTVkZmM5NTgzY2Y1OWU=",
                "author": {
                  "name": "Erlang/OTP",
                  "date": "2017-09-13T10:36:24.000+02:00"
                }
              }
            }
          },
          {
            "cursor": "MTAx",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTNCMDM=",
              "name": "OTP_R13B03",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjBlMzQ4ZWNlMDFmM2Q2NzU0NjQ0YWEyYjc4ZjA2NzEwNWQ5MGVjZjM=",
                "author": {
                  "name": "Erlang/OTP",
                  "date": "2009-11-20T15:54:40.000+01:00"
                }
              }
            }
          },
          {
            "cursor": "MTAy",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTNCMDQ=",
              "name": "OTP_R13B04",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjNlYmI4N2NjOWNiOWNmNDA1ZmIxMGIzMzkyM2U5ZDFhMGU5MWY0YzE=",
                "author": {
                  "name": "Erlang/OTP",
                  "date": "2010-02-19T19:11:35.000+01:00"
                }
              }
            }
          },
          {
            "cursor": "MTAz",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRB",
              "name": "OTP_R14A",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjY2MWUxMWY0ZDlhZjIzOTJhMTg4MGQxNDJiNmQ3MzcyZWE4Njg5MjA=",
                "author": {
                  "name": "Erlang/OTP",
                  "date": "2010-06-17T10:39:22.000+02:00"
                }
              }
            }
          },
          {
            "cursor": "MTA0",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRC",
              "name": "OTP_R14B",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjUyYTk4NWY3ZGExNGFhZGE1YWI5ZGNkMDMwMzAxMzdkYjI1N2E4YTI=",
                "author": {
                  "name": "Björn-Egil Dahlberg",
                  "date": "2010-09-14T13:54:24.000+02:00"
                }
              }
            }
          },
          {
            "cursor": "MTA1",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRCMDE=",
              "name": "OTP_R14B01",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OmM0OWU2NDRlZmM5M2RkOTk4NDFjZmViZTM0ZWMyYjY4NGU4ZmZmNTM=",
                "author": {
                  "name": "Patrik Nyblom",
                  "date": "2010-12-07T15:46:05.000+01:00"
                }
              }
            }
          },
          {
            "cursor": "MTA2",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRCMDI=",
              "name": "OTP_R14B02",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjczYjQyMjE1MmI4NTUxYTQ5ZWYxZjQyZGE1NjI0ZmZhOWMwNTBjYjE=",
                "author": {
                  "name": "Björn-Egil Dahlberg",
                  "date": "2011-03-15T14:06:05.000+01:00"
                }
              }
            }
          },
          {
            "cursor": "MTA3",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRCMDM=",
              "name": "OTP_R14B03",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OmU0MTY4MTQyYzc1ZTcxYzM3YjM0NjQwMjQ5MWVkMDk5NzQwYjM2MGQ=",
                "author": {
                  "name": "Björn-Egil Dahlberg",
                  "date": "2011-05-25T09:11:50.000+02:00"
                }
              }
            }
          },
          {
            "cursor": "MTA4",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTRCMDQ=",
              "name": "OTP_R14B04",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjcwMWJlYTA2ZTZhNzU3ZTA3MzRjMmIwZWQwZmRmNGE2MGUxOTY5ZmE=",
                "author": {
                  "name": "Björn-Egil Dahlberg",
                  "date": "2011-10-04T15:46:29.000+02:00"
                }
              }
            }
          },
          {
            "cursor": "MTA5",
            "node": {
              "id": "MDM6UmVmMzc0OTI3Ok9UUF9SMTVB",
              "name": "OTP_R15A",
              "target": {
                "id": "MDM6VGFnMzc0OTI3OjNiYjRiYWMzNjNhZmUxNmRkMDNiYjRjZjc2MjlkZDEzMjg5OTY5Mjc=",
                "author": {
                  "name": "Björn-Egil Dahlberg",
                  "date": "2011-11-22T11:57:52.000+01:00"
                }
              }
            }
          }
        ],
        "pageInfo": {
          "endCursor": "MTA5",
          "hasNextPage": true,
          "hasPreviousPage": false,
          "startCursor": "MTAw"
        }
      }
    }
  }
}

Notice that tag OTP-20.0.5 was created at 2017-09-13T10:36:24.000+02:00 is the first in list allthough it has the latest creation date.

Tags like OTP_R13B03 are later in list event though it is created almost 8 years ago.

When I base64 decode the cursor values I see that the cursor of OTP_R13B03 (MTAx => 101) is indeed higher than the cursor of OTP-20.0.5 (MTAw => 100).

This led to the problem that I can’t get new tags reliable because when OTP-20.0.6 is released, the assigned curser might be smaller than MTA5 (the current latest cursor). So I will miss this new tag.

Hint: This already happened when 20.0.5 was released.

Might this be a bug due to the sorting of base64 encoded strings? ("MTA0" is greater than "MTAz" but is alphabetically sorted before "MTAz")


#2

I figured it out. sorting order is based on the name of the node. The cursor is just a counter, so new releases can pop up in the middle.

This implies that I have to fetch all tags to figure out which are new.

Or is there any way to sort tags by date?


#3

Hi @leifg!

Sorry I haven’t responded sooner to this - I was actually digging into this a while ago, I agree that it is quite confusing.

As far as I can tell, the issue is that we sort tags by alphabetical order, and not by the date of the attached commit.

I have a branch right now that would allow you to sort by the date of the underlying commit when using refs/tags/, which seems like the desired behavior.

Would that take care of what you’re looking for? I’ll open a PR and chat about it internally as well.


#4

Sorting by date would totally take care of the problem!

Thank you so much!


#5

Any news on this?


#6

Heya! Sorry for the late reply here. We opened a pull request about ~three weeks ago but go overwhelmed by some other work for the GitHub Universe conference, which was last week. I’ve bumped the PR for more input and we’ll get back to you when it’s moved along!


#7

That’s great news. Thanks for following up!


#8

Hey @leifg,

We’ve just shipped the orderBy argument to the refs controller. It accepts 2 different fields to sort by: ALPHABETICAL, the old behavior, and TAG_COMMIT_DATE, which sorts by commit date. The new orderBy argument is preferred over the old direction argument, which is now deprecated.

https://developer.github.com/v4/reference/object/repository/

Thanks for the feature request!