Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-pull-request

GitHub Action

PR Compliance Action

v0.3.0 Pre-release

PR Compliance Action

git-pull-request

PR Compliance Action

Action to check PR compliance on various aspects to improve maintainer QOL.

Installation

Copy and paste the following snippet into your .yml file.

              

- name: PR Compliance Action

uses: mtfoley/[email protected]

Learn more about this action in mtfoley/pr-compliance-action

Choose a version

pr-compliance-action

This action is meant to help in managing inbound PRs that may need adjustment other than code.

Functionality

It looks for the following:

  • PR Title formatted according to conventional commits.
  • PR Body refers to an issue, as detected by a regular expression
  • PR originates from a protected branch e.g. "main", (based on head ref)
  • PR includes modifications to specific files that should be reviewed carefully (e.g. package.json)

Sample Workflow File

Below is a sample yaml file to place in .github/workflows/:

name: PR Compliance

on:
  pull_request:
    types: [opened, edited, reopened]

# Action should have write permission to make updates to PR
permissions:
  pull-requests: write

jobs:
  pr-compliance:
    runs-on: ubuntu-latest
    steps:
      - uses: mtfoley/pr-compliance-action@main
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          protected-branch: 'master'
          watch-files: |
            package.json
            npm-shrinkwrap.json

Behavior

This action drives the following outcomes:

Check Outcome on Failure
PR Title Lint Action shows as failed check. Action leaves comment.
PR Refers to Issue Action closes issue. Action leaves comment.
PR Originates from Protected Branch Action closes issue. Action leaves comment.
PR Avoids Watched Files Action leaves comment.

Inputs

All inputs are required and all have default values. The only input absolutely require to be specified in a workflow file is the repo-token input.

Name Default Description
repo-token (Blank) Access token for which this action will run. This action uses @actions/core library.
ignore-authors dependabot
dependabot[bot]
If the action detects that the PR author is one of these logins, it will skip checks and set all outputs to true.
base-comment (see action.yml) Preamble to any comment the action leaves on the PR.
ignore-team-members true Whether to ignore in the case that the PR author is a) the owner of repository, or b) has a public membership1 in the org that owns the repository.
body-regex (fix|resolv|clos)(e)*(s|d)* #\d+ Regular expression to identify whether the PR body refers to an issue2.
body-auto-close true Whether or not to auto-close on failed check of PR Body
body-comment (see action.yml) Comment to leave on PR on failed check of PR Body
protected-branch (Blank) Branch that check should ensure that PR does not use as it's head. If left blank, it falls back to default branch.
protected-branch-auto-close true Whether or not to auto-close on failed check of PR head branch
protected-branch-comment (see action.yml) Comment to leave on PR on failed check of PR head branch.
title-check-enable true Whether or not to lint PR title per conventional commits.
title-comment (see action.yml) Comment to leave on PR on failed check of PR title per conventional commits
watch-files (Blank) Files to flag for modifications (e.g. package.json)
watch-files-comment (see action.yml) Comment to leave on PR when watched files have been changed.

Outputs

Each check performed is also manifested in an output.

Name Description
body-check Result of match for PR Body against configured regex.
branch-check Result of check to ensure PR head is not protected branch.
title-check Result of check to ensure PR title is formatted per conventional commits
watch-files-check Result of check for watched files having been modified. True if no modifications found to watched files.

Footnotes

  1. In a case where a contributor has a private membership to the org, the ignore-authors may be used to skip checks - however, this workflow file configuration could effectively make membership public.

  2. Default regular expression is based on linking to an issue using a keyword. To keep PRs related to issues within the same same repo, we use the KEYWORD #ISSUE-NUMBER syntax. However, one could also use a regular expression like (fix\|resolv\|clos)(e)*(s|d)* (my-org)\/([a-z0-9\-_]*)#\d+