有没有什么快速的方法来获取所有打开的拉取请求的评论数

Is there any quick way to get comment count of all open pull request

我需要在存储库的所有打开的拉取请求中查找评论数

我知道的唯一方法是从存储库获取所有打开的拉取请求并迭代每个拉取请求并执行这样的调用

GET /repos/:owner/:repo/pulls/:pull_number/comments

并总结这些反应,但成本太高

我也试过这个方法(在一个 repo 中查找所有 PR 的评论)

GET /repos/:owner/:repo/pulls/comments

并像这样传递 state = open 作为查询参数

https://api.github.com/repos/angular/angular/pulls/comments?per_page=30&state=open

但是它 returns 审核所有拉取请求的评论

我们将不胜感激

使用 Github API Rest v3,您可以使用这样的搜索查询:

https://api.github.com/search/issues?q=is:pr%20state:open%20repo:angular/angular&per_page=100

您可以通过以下查询使用 GraphQL API v4

{
  repository(owner: "angular", name: "angular") {
    pullRequests(states: OPEN, first: 100) {
      nodes {
        title
        comments {
          totalCount
        }
      }
    }
  }
}

Try it in the explorer

或者使用这样的搜索查询:

{
  search(type: ISSUE, query: "is:pr state:open repo:angular/angular", first: 100) {
    nodes {
      ... on PullRequest {
        title
        comments {
          totalCount
        }
      }
    }
  }
}

Try it in the explorer

如果你想要评论计数和评论评论,你可以使用:

{
  search(type: ISSUE, query: "is:pr state:open repo:angular/angular", first: 100) {
    nodes {
      ... on PullRequest {
        title
        comments {
          totalCount
        }
        reviews(first: 100) {
          totalCount
          nodes {
            comments {
              totalCount
            }
          }
        }
      }
    }
  }
}

Try it in the explorer

使用

repo_owner=angular
repo_name=angular
token=YOUR_TOKEN

curl -s -H "Authorization: bearer $token" -d '
{
    "query": "query {repository(owner: \"'$repo_owner'\", name: \"'$repo_name'\") {pullRequests(states: OPEN, first: 100) {nodes {title comments {totalCount}}}}}"
}
' https://api.github.com/graphql