'Get No. of approvals on a pull request using github's graphql api

I'm trying to get the number of approvals a pull request has received. I can get the number of reviews, but that includes all reviews whether approved, rejected, comments etc.

```
{
  search(query: "type:pr state:open involves:${username}", type: ISSUE, first: 10) {
      edges {
      node {
        ... on PullRequest {
          reviews {
            totalCount
          }
        }
      }
    }
  }
}

```

is there a way to get just the approvals?



Solution 1:[1]

Looks like you just need to look at the state field of a review to see if it was approved. Seems like it would be pretty easy to just loop though each review and count the approvals that way.

https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request

Solution 2:[2]

For receiving only the approvals, we can use the the state argument and pass in APPROVED. To get the total count, GitHub can return this without the need to loop through results. Simply ask for totalCount.

Here's a simple working snippet:

{
  repository (owner: "YOUR_ORG" name: "YOUR_REPO_NAME") {
    pullRequests (first: 100) {
      edges {
        node {
          reviews (first: 100 states: APPROVED) {
            totalCount
          }
        }
      }
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 spencer.sm
Solution 2 joematune