如何使用github API获取Github Pull请求注释线程

时间:2020-05-30 13:26:38

标签: github

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

我需要这样的公关评论

ex) enter image description here

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

有没有可以使用的API?

请找到它。

1 个答案:

答案 0 :(得分:0)

Rest API v3

使用API​​ v3,您可以使用

获取PR注释
https://api.github.com/repos/OWNER/REPO_NAME/issues/NUMBER/comments

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

您可以使用:

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

this 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

this 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
      }
    }
  }
}
相关问题