使用 Github Api V4 从 Github 仓库获取最后 x 次提交

Get last x commits from Github repo using Github Api V4

我正在尝试使用新的 Github GraphQL api (v4),但我似乎无法弄清楚如何获取 [=28 的最后 x 次提交=]大师。我已经使用了 repositoryref 但他们仍然没有给我我需要的东西。

下面的查询几乎可以满足我的需求:

query{
  repository(owner: "typelevel", name: "cats") {
    refs(refPrefix:"refs/heads/", last: 5) {
      edges{
        node {
          associatedPullRequests(states: MERGED, last: 5) {
            edges{
              node {
                title
                baseRef {
                  name
                  prefix
                }
                baseRefName
                commits(last: 10) {
                  edges {
                    node {
                      commit {
                        abbreviatedOid
                        message

                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

但是:

  1. 似乎与存储库中的内容不完全匹配
  2. 限于 PR
  3. 好像太笨重了

我也试过使用 defaultBranchRef 但这也不起作用:

query{
  repository(owner: "typelevel", name: "cats") {
    defaultBranchRef {
      name
      prefix
      associatedPullRequests(states: [MERGED], last: 5) {
        edges {
          node {
            title
          }
        }
      }
    }
  }
}

我一直在 Github api 页面上使用 explorer app 测试查询。

有什么想法吗?

在这种情况下使用 history 会更好吗?

this thread

A "ref" (short for reference) is anything that points to a git commit. This could be a local branch, a tag, a remote branch, etc. So master, for example, would be considered a ref.

In that vein, you can use the ref field on the Repository type to get a reference that targets a commit.
From that commit, you can get all of the commit's parents. If you target master, you can get the main history of the git repository.

query {
  node(id: "MDEwOlJlcG9zaXRvcnk4NDM5MTQ3") {
    ... on Repository {
      ref(qualifiedName: "master") {
        target {
          ... on Commit {
            id
            history(first: 30) {
              totalCount
              pageInfo {
                hasNextPage
              }

              edges {
                node {
                  oid
                  message
                  author {
                    name
                    email
                    date
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

我能够使用它:

query {
  repository(owner: "typelevel", name: "cats") {
    ref(qualifiedName: "master") {
      target {
        ... on Commit {
          history(first: 10) {
            pageInfo {
              hasNextPage
              endCursor
            }
            edges {
              node {
                oid
                messageHeadline
              }
            }
          }
        }
      }
    }
  }
}

通过修改 this query linked to on the Github Platform Community.