Github GraphQL - 获取存储库的提交列表 [英] Github GraphQL - Getting a repository's list of commits
问题描述
我正在使用 GraphQL 从使用 Github 的 GraphQL (v4) API 的存储库列表中获取一些数据.我想从存储库中获取最新提交的列表,无论提交的分支/标签/引用是什么.
I am using GraphQL to get some data from a list of repositories using Github's GraphQL (v4) API. I want to get a list of the latest commits from a repository, no matter what is the commit's branch/tag/ref.
现在我正在执行以下操作以从某个存储库中获取提交列表:
For now I am doing the following to get the list of commits from a certain repository:
... on Repository{
refs(refPrefix:"refs/",orderBy:$refOrder,first:1){
edges{
node{
... on Ref{
target{
... on Commit{
history(first:10){
totalCount
edges{
node{
... on Commit{
committedDate
}
}
}
}
}
}
}
}
}
}
}
其中 $refOrder
是我与请求一起发送的对象,其定义如下:
Where $refOrder
is an object I am sending together with the request and it is defined below:
{
"refOrder": {
"direction": "DESC",
"field": "TAG_COMMIT_DATE"
}
}
这段代码正在运行,但没有检索到我想要的结果.响应返回一个提交列表,但不一定是来自存储库的最后提交.当我转到存储库页面并单击提交"时,我通常会看到一个提交列表,这些提交列表比我从 API 调用中获得的结果更新.
This piece of code is working, but not retrieving the results I want. The response comes back with a list of commits, but not necessarily the last commits from the repository. When I go to the repository page and click on "Commits", I usually see a list of commits that are more recent than what I got as results from my API call.
我错过了什么?我应该尝试不同的 refPrefix
或 orderBy
参数吗?我已经尝试将master"作为 refPrefix
,但遇到了同样的问题.
What am I missing? Should I try a different refPrefix
or orderBy
argument? I have already tried "master" as the refPrefix
, but faced the same problem.
推荐答案
刚刚意识到我正在寻找的是一个名为 defaultBranchRef
的Repository
对象中存在的字段.使用这个字段,我能够检索到我正在寻找的数据.
Just realized that what I was looking for is a field which exists in the Repository
object called defaultBranchRef
. Using this field I was able to retrieve the data I was looking for.
我的查询现在看起来像这样:
My query now looks like this:
... on Repository{
defaultBranchRef{
target{
... on Commit{
history(first:10){
edges{
node{
... on Commit{
committedDate
}
}
}
}
}
}
}
}
这篇关于Github GraphQL - 获取存储库的提交列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!