Github API(v3):按创建日期对搜索结果进行排序

时间:2017-11-13 01:07:09

标签: github github-api

我想按照创建日期对存储库搜索结果进行排序。 这可能是一件容易的事,但我一直在苦苦挣扎。 请帮忙:(

2 个答案:

答案 0 :(得分:2)

如果仍然可以选择Github API Graphql v4,那么您可以从the explorer轻松完成此任务:

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

使用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

答案 1 :(得分:2)

对于API(V3),您可以在查询中包含排序限定符 - +sort:author-date-desc表示降序,+sort:author-date-asc表示升序。

例如:要搜索由km-poonacha按升序排序的所有存储库,您可以进行以下搜索请求:

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

参考:Sorting Search Results