Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API (v3): Order tags by creation date

I ran into a problem / question while using the GitHub API.

I need a list of all tags created after a single tag. The only way to do this, is to compare the tags by date. However, the results from the API aren't ordered by date:

Result from the API (rails repository example):

API results

Results from the webinterface:

Webinterface results

What i did expect is a list ordered by date. However, as you can see in the pictures: the API is returning v4.0.0rc1 & v4.0.0rc2 before the release of v4.0.0, while 4.0.0 is released after the release candidates. There isn't even a creation / commit date to order at server side.

The releases API isn't a solution either. This API is only returning releases created by Github, not the releases created by tags.

Is there any way to order the tags by date?

Thanks in advance!

Ruben

like image 200
Ruben Ernst Avatar asked Oct 18 '13 14:10

Ruben Ernst


People also ask

How do I get new GitHub tags?

get-latest-tag-on-git.sh # The command finds the most recent tag that is reachable from a commit. # If the tag points to the commit, then only the tag is shown. # and the abbreviated object name of the most recent commit.

How do I see tags on GitHub?

Viewing tags On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases. At the top of the Releases page, click Tags.

Does a GitHub release create a tag?

Releases are based on Git tags, which mark a specific point in your repository's history. A tag date may be different than a release date since they can be created at different times. For more information about viewing your existing tags, see "Viewing your repository's releases and tags."

Does GitHub have tags?

About tags in GitHub DesktopGitHub Desktop allows you to create annotated tags. Tags are associated with commits, so you can use a tag to mark an individual point in your repository's history, including a version number for a release. For more information about release tags, see "About releases."


2 Answers

The Repositories API currently returns tags in the order they would be returned by the "git tag" command, which means they are alphabetically sorted.

The problem with sorting tags chronologically in Git is that there are two types of tags, lightweight and annotated), and for the lightweight type Git doesn't store the creation date.

The Releases/Tags UI currently sorts tags chronologically by the date of the commit to which the tag points to. This again isn't the date on which the tag itself was created, but it does establish a chronological order of things.

Adding this alternative sorting option to the API is on our feature request list.

like image 52
Ivan Zuzak Avatar answered Oct 10 '22 15:10

Ivan Zuzak


With GraphQL API v4, we can now filter tags by commit date with field: TAG_COMMIT_DATE inside orderBy. The following will perform ascending sort of tags by commit date :

{
  repository(owner: "rails", name: "rails") {
    refs(refPrefix: "refs/tags/", last: 100, orderBy: {field: TAG_COMMIT_DATE, direction: ASC}) {
      edges {
        node {
          name
          target {
            oid
            ... on Tag {
              message
              commitUrl
              tagger {
                name
                email
                date
              }
            }
          }
        }
      }
    }
  }
}

Test it in the explorer

Here, the tagger field inside target will only be filled for annotated tag & will be empty for lightweight tags.

As date property in tagger gives the creation date of the tag (for annotated tag only), it's possible to filter by creation date on the client side easily (without having to retrieve all the tags 1 by 1)

Note that available options for orderBy.field at this time are TAG_COMMIT_DATE & ALPHABETICAL (no TAG_CREATION_DATE)

like image 39
Bertrand Martel Avatar answered Oct 10 '22 14:10

Bertrand Martel