首页 > 解决方案 > 如何使用 github API 获取 Github 拉取请求评论线程

问题描述

https://developer.github.com/v3/pulls/

我需要这样的 PR 评论

前任) 在此处输入图像描述

[
    {
        avartar : 'img_link',
        author : 'MoonSupport',
        description: 'dd\ntt',
    },
    {
        avartar : 'img_link',
        author : 'MoonSupport',
        description: 'review1',
    },
    {
        avartar : 'img_link',
        author : 'MoonSupport',
        description: 'review2',
    }
]

有 API 可以工作吗?

请找到它。

标签: github

解决方案


休息 API v3

使用 API v3,您可以使用以下方式获取 PR 评论

https://api.github.com/repos/OWNER/REPO_NAME/issues/NUMBER/comments

此 PR的示例:https ://api.github.com/repos/mui-org/material-ui/issues/21214/comments

您可以使用以下方式获取 PR 审查意见:

https://api.github.com/repos/OWNER/REPO_NAME/pulls/NUMBER/comments

此 PR的示例:https ://api.github.com/repos/mui-org/material-ui/pulls/21214/comments

但这不包括评论正文(与 Github Web UI 中的评论处于同一级别)。以下获取评论的正文:

https://api.github.com/repos/OWNER/REPO_NAME/pulls/NUMBER/reviews

此 PR的示例:https ://api.github.com/repos/mui-org/material-ui/pulls/21214/reviews

GraphQL API v4

使用GraphQL API获取评论、评论评论和评论正文:

{
  repository(name: "material-ui", owner: "mui-org") {
    pullRequest(number: 21214) {
      reviews(first: 100) {
        nodes {
          bodyText
          createdAt
          author {
            login
          }
          comments(first: 100) {
            nodes {
              author {
                login
              }
              body
            }
          }
        }
      }
      comments(first: 100) {
        nodes {
          author {
            login
          }
          createdAt
          body
        }
        totalCount
      }
    }
  }
}

推荐阅读