GitHunt
PA

patricklubach/reviewer-action

A GitHub action that checks approvals of a PR to match defined rules.

reviewer-action

This action checks if all approvals of a PR match given rules.

Inputs

gh_token

Required The Github token to access the repository to check.

reviewers_file

Optional The path to the file where reviewer rules are defined. The syntax
of the file is as follows:

check_on: title

rules:
  - regex: ^feature/
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9
  - regex: ^bugfix/
    reviewers:
      - user:Foo

Default: .reviewers.yaml

Outputs

None

Example usage

When you want to let the action set the reviewers for each pull request for you:

name: Set reviewers

on:
  pull_request:
    types:
      - opened
      - reopened
      - ready_for_review

permissions:
  contents: read
  pull-requests: write

jobs:
  set_reviewers:
    name: Set reviewers
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4

      - name: Install Dependencies
        id: npm-ci
        run: npm ci

      - name: Set reviewers
        uses: ./
        with:
          reviewers_file: .reviewers.yaml
          token: ${{ secrets.GITHUB_TOKEN }}
          pr_number: ${{ github.event.pull_request.number }}
          set_reviewers: true

When you want to let the action check the reviews when a review was dismissed or
submitted:

name: Check reviews

on:
  pull_request_review:
    types: [dismissed, submitted]

permissions:
  contents: read
  pull-requests: write

jobs:
  check_reviews:
    name: Check reviews
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        id: checkout
        uses: actions/checkout@v4

      - name: Install Dependencies
        id: npm-ci
        run: npm ci

      - name: Check reviews
        id: check-reviews
        uses: ./
        with:
          reviewers_file: .reviewers.yaml
          token: ${{ secrets.GITHUB_TOKEN }}
          pr_number: ${{ github.event.pull_request.number }}

Configuration examples

In the following there is a minimal example of the .reviewers.yaml file. If no
other option is being used then every listed reviewer needs to approve the PR to
fulfill the requirement. If a team is defined then each member of the team needs
to approve the PR.

rules:
  - regex: ^feature/
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9

You can limit how many reviewers need to approve the pull request by setting the
count keyword:

rules:
  - regex: ^feature/
    count: 1
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9

You can have different rules for defined regex pattern like below:

rules:
  - regex: ^feature/
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9
  - regex: ^bugfix/
    reviewers:
      - user:Foo

You can also define a default rule which is identified by the default keyword.
If you have multiple default rules defined the first which is found is being
returned and is applied to the PR:

rules:
  - regex: ^feature/
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9
  - regex: ^bugfix/
    reviewers:
      - user:Foo
  - default: true
    reviewers:
      - user:Foo

In default configuration the reviewer action is checking on the branch of the
pull request. You can configure that behaviour by setting the check_on
configuration on a per rule base:

check_on: branch

rules:
  - regex: ^feature/
    reviewers:
      - team:MyreviewerGroup
      - user:RobotUser9
  - regex: ^bugfix/
    reviewers:
      - user:Foo
  - default: true
    reviewers:
      - user:Foo

Test locally

To test the action locally, first install
act. Then you need to create a event.json
file to match an already open pull request. For more information see
act documentation.
Afterwards you can simply run:

npm run test:local:check

Languages

TypeScript99.0%JavaScript0.6%Shell0.4%

Contributors

MIT License
Created June 14, 2024
Updated March 4, 2026