ZenHub APIを使ってBoard Pipeline上のIssueを取得する

2021.03.16

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

ZenHubについて

ZenHubはGitHub Issueをチケットとしてカンバン方式で進捗などを管理するプロジェクト管理ツールです。GitHubとZenHubを連携することで、各Issueの進捗状況を細かく管理することができます。

ZenHub APIについて

ZenHubはWeb APIを提供しており、REST APIを通してブラウザの代わりに操作することができます。

APIの使い方はGitHub上にまとめられています。また、アクセスする際に必要となるTokenはここから発行することができます。

DashBoardの取得

試しにDashBoard上にあるIssueを取得してみます。以下がDashBoardにアクセスするためのエンドポイントです。

GET /p2/workspaces/:workspace_id/repositories/:repo_id/board

対象となるworkspace_Id はZenHubから、 repo_id はGitHubから取得することができます。

$ curl -H 'X-Authentication-Token:xxxxxxx' https://api.zenhub.com/p2/workspaces/aaaaaaaaaaa/repositories/1111111111/board | jq . | head -n 30
{
  "pipelines": [
    {
      "id": "xxxxxxxxxxxxxxxx",
      "name": "New Issues",
      "issues": [
        {
          "issue_number": 56,
          "is_epic": true,
          "position": 61
        },
        {
          "issue_number": 111,
          "is_epic": true,
          "position": 62
        },
        {
          "issue_number": 656,
          "is_epic": true,
          "position": 63
        },
        {
          "issue_number": 576,
          "is_epic": false,
          "estimate": {
            "value": 13
          },
          "position": 64
        },
        {

各Pipeline毎のチケット件数を出してみます。

$ curl -H 'X-Authentication-Token:xxxxxxx' https://api.zenhub.com/p2/workspaces/aaaaaaaaaaa/repositories/1111111111/board | jq '.pipelines[] as $p | $p.name as $name | $p.issues | length as $count | {name: $name, count: $count}'

{
  "name": "New Issues",
  "count": 107
}
{
  "name": "Icebox",
  "count": 12
}
{
  "name": "Backlog",
  "count": 46
}
{
  "name": "In Progress",
  "count": 15
}
{
  "name": "Review/QA",
  "count": 19
}
{
  "name": "Done",
  "count": 4
}

出せました。

参考