Github GraphQL - 获取存储库的提交列表
Github GraphQL - Getting a repository's list of commits
我正在使用 GraphQL 从使用 Github 的 GraphQL (v4) API 的存储库列表中获取一些数据。我想从存储库中获取 最新提交 的列表,无论提交的 branch/tag/ref.
是什么
现在我正在执行以下操作以从某个存储库获取提交列表:
... 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
是我与请求一起发送的对象,定义如下:
{
"refOrder": {
"direction": "DESC",
"field": "TAG_COMMIT_DATE"
}
}
这段代码有效,但没有检索到我想要的结果。响应返回一个提交列表,但不一定是来自存储库的最后一次提交。当我转到存储库页面并单击 "Commits" 时,我通常会看到比我从 API 调用中获得的结果更新的提交列表。
我错过了什么?我应该尝试不同的 refPrefix
或 orderBy
参数吗?我已经尝试 "master" 作为 refPrefix
,但遇到了同样的问题。
刚刚意识到我正在寻找的是 Repository
对象中存在的一个名为 defaultBranchRef
的字段。使用此字段,我能够检索到我正在寻找的数据。
我的查询现在看起来像这样:
... on Repository{
defaultBranchRef{
target{
... on Commit{
history(first:10){
edges{
node{
... on Commit{
committedDate
}
}
}
}
}
}
}
}
如果您也有兴趣获取所有分支(不仅仅是默认分支)的最新提交,您可以请求前缀为 refs/heads/
的参考:
{
repository(owner: "bertrandmartel", name: "callflow-workshop") {
refs(refPrefix: "refs/heads/", orderBy: {direction: DESC, field: TAG_COMMIT_DATE}, first: 100) {
edges {
node {
... on Ref {
name
target {
... on Commit {
history(first: 2) {
edges {
node {
... on Commit {
committedDate
}
}
}
}
}
}
}
}
}
}
}
}
在你的情况下使用 refs/
也给了你标签 ref.
我正在使用 GraphQL 从使用 Github 的 GraphQL (v4) API 的存储库列表中获取一些数据。我想从存储库中获取 最新提交 的列表,无论提交的 branch/tag/ref.
是什么现在我正在执行以下操作以从某个存储库获取提交列表:
... 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
是我与请求一起发送的对象,定义如下:
{
"refOrder": {
"direction": "DESC",
"field": "TAG_COMMIT_DATE"
}
}
这段代码有效,但没有检索到我想要的结果。响应返回一个提交列表,但不一定是来自存储库的最后一次提交。当我转到存储库页面并单击 "Commits" 时,我通常会看到比我从 API 调用中获得的结果更新的提交列表。
我错过了什么?我应该尝试不同的 refPrefix
或 orderBy
参数吗?我已经尝试 "master" 作为 refPrefix
,但遇到了同样的问题。
刚刚意识到我正在寻找的是 Repository
对象中存在的一个名为 defaultBranchRef
的字段。使用此字段,我能够检索到我正在寻找的数据。
我的查询现在看起来像这样:
... on Repository{
defaultBranchRef{
target{
... on Commit{
history(first:10){
edges{
node{
... on Commit{
committedDate
}
}
}
}
}
}
}
}
如果您也有兴趣获取所有分支(不仅仅是默认分支)的最新提交,您可以请求前缀为 refs/heads/
的参考:
{
repository(owner: "bertrandmartel", name: "callflow-workshop") {
refs(refPrefix: "refs/heads/", orderBy: {direction: DESC, field: TAG_COMMIT_DATE}, first: 100) {
edges {
node {
... on Ref {
name
target {
... on Commit {
history(first: 2) {
edges {
node {
... on Commit {
committedDate
}
}
}
}
}
}
}
}
}
}
}
}
在你的情况下使用 refs/
也给了你标签 ref.