首页 > 解决方案 > 如何使用 GitHub GraphQL API 在项目中的列之间移动问题?

问题描述

我想使用 GitHub GraphQL API确定卡片何时在GitHub 项目板中从一列移动到另一列。

我可以使用如下查询列出项目板(例如Twitter Bootstrap)中的所有问题:

{
  organization(login: "twbs") {
    repository(name: "bootstrap") {
      project(number: 4) {
        columns(first: 5) {
          nodes {
            name
            cards(first: 10) {
              nodes {
                content {
                  __typename
                  ... on Issue {
                    title
                    url
                    timeline(first: 10) {
                      nodes {
                        __typename
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

中的事件类型很多IssueTimelineConnection,但与项目相关的事件不在其中:

...
{
  "content": {
    "__typename": "Issue",
    "title": "Remove inner white border effect on popovers",
    "url": "https://github.com/twbs/bootstrap/issues/23763",
    "timeline": {
      "nodes": [
        {
          "__typename": "RenamedTitleEvent"
        },
        {
          "__typename": "IssueComment"
        },
        {
          "__typename": "LabeledEvent"
        },
        {
          "__typename": "LabeledEvent"
        },
        {
          "__typename": "IssueComment"
        },
        {
          "__typename": "CrossReferencedEvent"
        },
        {
          "__typename": "CrossReferencedEvent"
        },
        {
          "__typename": "LabeledEvent"
        },
        {
          "__typename": "ClosedEvent"
        },
        {
          "__typename": "CrossReferencedEvent"
        }
      ]
    }
  }
...

我可以看到问题何时在 GitHub 网页上针对该问题的列之间移动:

图片

我只是在 API 中看不到这些事件。这是缺少的功能吗?还有其他方法可以获取此信息吗?(背景:我想为 GitHub Project Boards 建立一个燃尽图。)

标签: githubgraphqlgithub-apigithub-graphqlgithub-projects

解决方案


您需要为项目事件详细信息 ( https://developer.github.com/v4/previews/#project-event-details )添加 Accept 标头,为问题预览 ( https://developer.github.com添加 Accept 标头/v4/previews/#issues-preview )

然后您可以使用timelineItems并运行这样的查询:

query {
  repository(owner: "buildo", name: "react-components") {
    issue(number: 1321) {
      timelineItems(first: 10) {
        nodes {
          __typename
        }
      }
    }
  }
}

这将返回:

{
  "repository": {
    "issue": {
      "timelineItems": {
        "nodes": [
          {
            "__typename": "ConvertedNoteToIssueEvent"
          },
          {
            "__typename": "AssignedEvent"
          },
          {
            "__typename": "LabeledEvent"
          },
          {
            "__typename": "MovedColumnsInProjectEvent"
          }
        ]
      }
    }
  }
}

推荐阅读