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

家住魔仙堡 提交于 2019-12-23 21:20:35

问题


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


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/47255773/github-apiv3-sort-search-result-by-date-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!