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
自变量吗?我已经尝试过将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.
推荐答案
我刚刚意识到我要找的是一个在Repository
对象中称为defaultBranchRef
的字段.使用此字段,我可以检索所需的数据.
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屋!