【问题标题】:Github API(v3): Sort search result by date createdGithub API(v3):按创建日期对搜索结果进行排序
【发布时间】:2018-04-25 15:07:30
【问题描述】:

我想按存储库的创建日期对存储库搜索结果进行排序。 这可能是一项容易的任务,但我已经挣扎了一段时间。 请帮忙:(

【问题讨论】:

标签: github github-api


【解决方案1】:

如果 Github API Graphql v4 仍然是一个选项,你可以很容易地做到这一点,来自the explorer

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

使用卷曲:

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

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

    例如:要搜索以km-poonacha 开始的所有repos,按升序排序,您可以发出以下搜索请求:

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

    参考:Sorting Search Results

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 2013-10-27
      • 1970-01-01
      • 2011-09-04
      • 2017-04-07
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多