github-actionspull-requestgithub-codereviews

How do I get the approvers of a pull request using GitHub Actions / Workflows?


In a GitHub Action.

From all of the reviewers of a pull request

The people who have approved said pull request

I want to get their username.


I am expecting there is a value I can pass to a "step" in the workflow. Something like how there is ${{ github.event.pull_request.body }}

I am wanting to get a value like: APPROVERS: ${{ github.event.pull_request.reviewers }} so I can parse it to a custom script.


Solution

  • Because there isn't anything in the default GitHub workflow specification (that I could find), I ended up just making this open-source GitHub Action that will get that info for you: https://github.com/marketplace/actions/get-github-pull-request-reviews

    Screenshot of the Get GitHub Pull Request Reviews action

    Easy as just adding this step into my workflow:

    - name: Get GitHub Pull Request Reviewers
      id: reviews
      # Versions come from https://github.com/LiamPerson/get-reviews-action/releases
      uses: LiamPerson/get-reviews-action@SPECIFY_ME # Specify the version you want by writing in a tag from the link above. E.g: v1.0
    

    Then consuming the result like so:

    - name: Consumes reviews
      uses: some/workflow@version
      with:
        RELEASES_JSON_FILE: ${{ steps.reviews.outputs.reviews_file_path }} # Note `reviews` is just the id used to identify the step earlier
    

    Only thing to be careful of is, this will just give you a file with the reviews rather than a JSON string as the string is too much to store in the Action variables.