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

GitHub Action

PR Title Checker

v1.3.7

PR Title Checker

tag

PR Title Checker

Checks if the PR Title follows contribution guidelines

Installation

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

              

- name: PR Title Checker

uses: thehanimo/[email protected]

Learn more about this action in thehanimo/pr-title-checker

Choose a version

Pull Request Title Checker

This action checks if PR titles conform to the Contribution Guidelines ☑️

Consistent title names help maintainers organise their projects better 📚

Shows if the author has reaaaaally read the Contribution Guidelines :P

Usage

Create a config file .github/pr-title-checker-config.json like this one below:

{
  "LABEL": {
    "name": "title needs formatting",
    "color": "EEEEEE"
  },
  "CHECKS": {
    "prefixes": ["fix: ", "feat: "],
    "regexp": "docs\\(v[0-9]\\): ",
    "regexpFlags": "i",
    "ignoreLabels" : ["dont-check-PRs-with-this-label", "meta"]
  },
  "MESSAGES": {
    "success": "All OK",
    "failure": "Failing CI test",
    "notice": ""
  }
}

You can pass in one of prefixes or regexp or even both based on your use case. regexpFlags and ignoreLables are optional fields.

If LABEL.name is set to "", adding or removing labels will be skipped. The CI test will continue to pass/fail accordingly.

If none of the checks pass, a label will be added to that pull request.
If at least one of them passes, the label will be removed.

This action causes CI tests to fail by default. However, if you do not want CI tests failing just because of this action, simply set alwaysPassCI as true in the CHECKS field. An invalid config file will always cause the action to fail.

Also, adding label names to the optional ignoreLabels field will forfeit any checks for PRs with those labels.

Create Workflow

Create a workflow (eg: .github/workflows/pr-title-checker.yml see Creating a Workflow file) to utilize the pr-title-checker action with content:

name: "PR Title Checker"
on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: thehanimo/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pass_on_octokit_error: false
          configuration_path: ".github/pr-title-checker-config.json"

NOTE:

  • pull_request_target event trigger should be used (not pull_request) in order to support checking PRs from forks. This was added in v1.3.2. See #8.

  • pass_on_octokit_error is an optional input which defaults to false. Setting it to true will prevent the CI from failing when an octokit error occurs. This is useful when the environment this action is run in is not consistent. For e.g, it could be a missing GITHUB_TOKEN. Thanks to @bennycode for pointing this out.

  • configuration_path is also an optional input which defaults to ".github/pr-title-checker-config.json". If you wish to store your config file elsewhere, pass in the path here.