有没有一种快速的方法来获取所有打开请求请求的评论计数

时间:2019-11-03 07:37:10

标签: github-api

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

我只知道从回购中获取所有打开的拉取请求并迭代每个拉取请求并执行这样的调用

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

总结这些回答,但这太昂贵了

我也尝试过这种方法(在回购中查找所有PR的评论注释)

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

并通过状态=像这样作为查询参数打开

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

但它会返回所有请求请求的评论注释

我们将不胜感激

1 个答案:

答案 0 :(得分:1)

使用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