Github API(v3): Sort search result by date created

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 :(

Upvotes: 4

Views: 6942

Answers (2)

Poonacha
Poonacha

Reputation: 1316

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

Upvotes: 4

Bertrand Martel
Bertrand Martel

Reputation: 45432

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

Upvotes: 6

Related Questions