如何找到使用github api批准拉取请求的用户?

时间:2017-01-17 12:41:35

标签: github github-api

例如,根据此拉取请求:https://github.com/harsh-groverfk/jenkins-demo/pull/16

如何查找已“批准”这些拉取请求中的更改的用户列表。

这是此拉取请求的示例评论:https://github.com/harsh-groverfk/jenkins-demo/pull/16#pullrequestreview-16967726

2 个答案:

答案 0 :(得分:4)

您可以使用List Reviews on a Pull Request API endpoint执行此操作。对于您列出的示例PR,这将是:

GET /repos/harsh-groverfk/jenkins-demo/pulls/16/reviews

另外请不要忘记这是preview-api,因此它需要Accept标题中的自定义媒体类型,但您可以在提供的链接中找到所有这些信息。

application/vnd.github.black-cat-preview+json

这将输出在PR上完成的所有评论(来自文档的示例):

[
  {
    "id": 80,
    "user": {
      "login": "octocat",
      "id": 1,
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",
      "followers_url": "https://api.github.com/users/octocat/followers",
      "following_url": "https://api.github.com/users/octocat/following{/other_user}",
      "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
      "organizations_url": "https://api.github.com/users/octocat/orgs",
      "repos_url": "https://api.github.com/users/octocat/repos",
      "events_url": "https://api.github.com/users/octocat/events{/privacy}",
      "received_events_url": "https://api.github.com/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    },
    "body": "Here is the body for the review.",
    "commit_id": "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091",
    "state": "APPROVED",
    "html_url": "https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80",
    "pull_request_url": "https://api.github.com/repos/octocat/Hello-World/pulls/12",
    "_links": {
      "html": {
        "href": "https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80"
      },
      "pull_request": {
        "href": "https://api.github.com/repos/octocat/Hello-World/pulls/12"
      }
    }
  }
]

答案 1 :(得分:1)

使用 GraphQL API

node_modules/package-name/build/Release/package-name.node

回复:

{
  repository(name: "jenkins-demo", owner: "harsh-groverfk") {
    pullRequest(number: 16) {
      reviews(first: 100, states: APPROVED) {
        nodes {
          author {
            avatarUrl
            login
            resourcePath
            url
          }
        }
      }
    }
  }
}

如果您没有具体的拉取请求编号,您可以查询 { "data": { "repository": { "pullRequest": { "reviews": { "nodes": [ { "author": { "avatarUrl": "https://avatars.githubusercontent.com/u/24560176?v=4", "login": "alekh2", "resourcePath": "/alekh2", "url": "https://github.com/alekh2" } } ] } } } } } 字段。