librariesio / libraries.io

:books: The Open Source Discovery Service
https://libraries.io
GNU Affero General Public License v3.0
1.1k stars 206 forks source link

Find Last Commit Date Out of Most Recent Batch of Commits #3301

Closed mikeyoung85 closed 5 months ago

mikeyoung85 commented 5 months ago

The GitHub GraphQL API does not seem to be consistent on which commit is the first returned. The order should be similar to what git log would return for the repository and there are some edge cases where a commit's data could have changed in a way where an older date commit is the first returned. This PR changes the query to look at the first 10 commits returned and find the latest date out of those. 10 is an arbitrary number but I didn't want the batch to be too big that it consumes more rate limit and the cases where I have found this to be a problem generally have the latest commit as the 2nd in the list returned from the query.

An example from https://github.com/dkubb/axiom-types/commits/master/

Query returns:

{
  "data": {
    "repository": {
      "defaultBranchRef": {
        "target": {
          "history": {
            "nodes": [
              {
                "committedDate": "2015-02-26T18:10:35Z"
              },
              {
                "committedDate": "2015-06-14T07:21:36Z"
              },
              {
                "committedDate": "2015-06-14T05:23:12Z"
              },
              {
                "committedDate": "2014-03-27T06:31:00Z"
              },
              {
                "committedDate": "2014-03-27T06:29:06Z"
              },
              {
                "committedDate": "2014-03-27T06:03:39Z"
              },
              {
                "committedDate": "2014-03-27T06:02:24Z"
              },
              {
                "committedDate": "2014-03-27T05:31:02Z"
              },
              {
                "committedDate": "2014-03-27T05:29:17Z"
              },
              {
                "committedDate": "2014-03-27T05:29:08Z"
              }
            ]
          }
        }
      }
    }
  }
}