/pr-custom-review

GitHub Action for complex pull request approval cases that are not currently supported by the Branch protection feature in GitHub.

Primary LanguageTypeScriptMIT LicenseMIT

PR Custom Review (GiHub Action)

This is an action created for complex pull request approval scenarios that are not currently supported by the protected branches feature in GitHub. It might extend or even completely replace Require pull request reviews before merging setting.

How this action works

Once setup, PR Custom Review action executed at events pull_request and pull_request_review (see workflow config example).

When the action is triggered, it evaluates whether PR contains changes requiring special approval. Conditions for evaluation specified in action's config_file and currently supports two types of checks:

  • pr_diff - examines PR diff content
  • pr_files - evaluates paths/files changed in PR

If PR Custom Review action detects that one of the conditions returns positive result it will request PR review from users/teams specified in the action's config and sets status check as failed preventing PR from merge until specified approval reviews count is received.

Then PR Custom Review action monitors pull_request_review events, evaluates received reviews and updates PR status checks accordingly.

Review policy described in action config can be enforced by setting status checks of PR's as required in the protected branch settings (see GitHub repository configuration).

Configuration

Action config

Action has one built-in condition check which evaluates whether PR changes any line of code containing 🔒 emoji sign or line below it.

Additional condition checks can be configured via the pr-custom-review-config.yml file placed in the .github subdirectory. Default config file can be overriden in workflow step with section. config_file is optional and if it is missing than only built-in check will be performed.

Config file format:

approval_groups:
  - name: CHECK NAME     # Used to create message in status check. Keep it short as description of status check has limit of 140 chars
    condition: /^.*$/    # RegExp used to detect changes. Do not specify modifiers after closing slash. "gm" modifiers will be added
    check_type: pr_diff  # Check type. Currently supported: `pr_diff` and `pr_files`
    min_approvals: 2     # Minimum required approvals
    users:               # GitHub users list to request review from
      - user1
      - user2
    teams:               # GitHub teams list to request review from. Must be within repository organization, teams from external organizations are not supported. Specify team name(slug) only e.g 'team1' without org. 'org/team1' will lead to failure.
      - team1
      - team2

Workflow config

name: PR Custom Review Status                     # Used to create status check name

on:                                               # Events which triggers action
  pull_request:
    branches:
      - main
      - master
    types:
      - opened
      - reopened
      - synchronize
      - review_request_removed                    # In addition to default events (opened, reopened, synchronize)
  pull_request_review:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2                 # IMPORTANT! use this action as the first step
        with:
          fetch-depth: 0
      - name: pr-custom-review
        uses: paritytech/pr-custom-review@master  # This action, please stick to the release, not master
        with:
          token: ${{ secrets.GITHUB_TOKEN }}            # If it is needed to request reviews from teams, then token with permission to read organization is needed. Default one created by GitHub action will fail.
          config-file: './.github/pr-custom-review-config.yml' # OPTIONAL: can be specified to override default config_file

GitHub repository configuration

Although action will work even without any additional settings in GitHub repository. It is recommended to setup Branch protection rules as shown on the screenshot below:

Expand screenshot

Branch protection settings

High level flow chart

High level flow chart