Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find users who approved a pull request using github api?

For example, given this pull request : https://github.com/harsh-groverfk/jenkins-demo/pull/16

How to find the list of users who have "approved" the changes in these pull requests.

this is an example review for this pull request : https://github.com/harsh-groverfk/jenkins-demo/pull/16#pullrequestreview-16967726

like image 362
user487478 Avatar asked Feb 05 '23 07:02

user487478


1 Answers

You can do this by using the List Reviews for a Pull Request API endpoint. For the example PR you've listed this would be:

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

This will output all reviews done on a PR (example from the docs):

[
  {
    "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"
      }
    }
  }
]
like image 145
bitoiu Avatar answered Feb 08 '23 16:02

bitoiu