3

I want to sort my repositories search result by the date they are created. This might be an easy task but I have been struggling for a while. Please help :(

  • You are wanting to "Sort Javascript Object Array By Date": https://stackoverflow.com/questions/10123953/sort-javascript-object-array-by-date, https://stackoverflow.com/questions/19430561/how-to-sort-a-javascript-array-of-objects-by-date, https://stackoverflow.com/questions/40965727/sort-array-of-objects-with-date-field-by-date – ESR Nov 13 '17 at 01:34

2 Answers2

3

If Github API Graphql v4 is still an option, you can do this very easily, from the explorer :

{
  user(login: "bertrandmartel") {
    repositories(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        createdAt
        name
      }
    }
  }
}

using curl :

curl -H "Authorization: bearer token" -d '
 {
   "query": "query { user(login: \"bertrandmartel\") { repositories(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { createdAt name } } } }"
 }
' https://api.github.com/graphql
Bertrand Martel
  • 32,363
  • 15
  • 95
  • 118
3

For API (V3) you can include the sort qualifier in your query - +sort:author-date-desc for descending and +sort:author-date-asc for ascending.

For example: to search all repos started by km-poonacha sorted ascending you can make the following search request:

https://api.github.com/search/repositories?q=user:km-poonacha+sort:author-date-asc

Ref: Sorting Search Results

Poonacha
  • 1,087
  • 1
  • 6
  • 18