Skip to content

pr-title-conventional

Included in config: 🔒 strict

A repository using this rule enforces that pull request titles follow the Conventional Commits format. Doing so helps to ensure that the purpose of a pull request is clear and consistent for humans and machines.

Specifically, keeping to the conventional commit format helps:

  • Humans: it becomes easier to categorize and understand pull request purposes quickly
  • Machines: automated tooling can parse those titles into semver-based releases

If a repository has this rule enabled, it’s likely aiming for either or both of those benefits.

This rule asks that titles be in either format:

type: body
type(scope): body
  • type: the conventional commit type, such as docs or fix
  • scope: an optional single sub-area, commonly a package name if a monorepo
  • body: a lower-case description

Example acceptable titles include:

docs: mention 'rick' feature in README.md
feat: add optional new 'roll' option to API
fix(parser): don't throw error on consecutive semicolons

This rule accepts the following rule options to restrict which titles are allowed:

  • types: an array of conventional commit types to allow instead of the default known types
    • Each type may contain ASCII letters, digits, and _ characters
  • scopes: an array of single scopes to allow; titles may still omit a scope
    • Each scope may contain ASCII letters, digits, spaces, and _$@.-*/ characters

For example, this configuration only allows docs, feat, and fix types, with scopes that are either omitted or are cli or parser:

.github/workflows/octoguide.yml
jobs:
octoguide:
runs-on: ubuntu-latest
steps:
- uses: OctoGuide/bot@0.33.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
rules: |
{
"pr-title-conventional": {
"scopes": [
"cli",
"parser"
],
"types": [
"docs",
"feat",
"fix"
]
}
}

These options restrict the subject portion of a title, after its type and optional scope:

  • subject-case: "lower" to ask that the subject not start with an upper-case letter
  • subject-trailing-punctuation: false to ask that the subject not end with !, ,, ., :, ;, or ?
  • subject-pattern: a regular expression the entire subject must match
  • subject-pattern-error: a sentence describing subject-pattern to report in place of the pattern itself

For example, this configuration asks for lower-case subjects without trailing punctuation, optionally prefixed with a bracketed list of rule names:

.github/workflows/octoguide.yml
jobs:
octoguide:
runs-on: ubuntu-latest
steps:
- uses: OctoGuide/bot@0.33.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
rules: |
{
"pr-title-conventional": {
"subject-case": "lower",
"subject-pattern": "^(\\[[a-z\\-]+(, [a-z\\-]+)*\\] )?[a-z].+$",
"subject-pattern-error": "PRs for rules should begin with \"[rule-name] \".",
"subject-trailing-punctuation": false
}
}

Pull request with a non-semantic title:

github-actions
👋 Hi @YourUsername, thanks for the issue! A scan flagged a concern with it. Could you please take a look?

[ pr-title-conventional ]

The PR title is missing a conventional commit type, such as “docs: “ or “feat: “. This repository asks that pull request titles start with a type in the Conventional Commits format. Doing so helps make the purpose of each pull request clear for humans and machines. To resolve this report, add a conventional commit type in front of the title, like “feat: Update README.md”.

Each snippet in this section shows changes to the full .github/workflows/octoguide.yml workflow from Get Started.

This rule is included in the strict config, which isn't enabled by default. To add it to the rules your workflow already runs, enable it in rules:

.github/workflows/octoguide.yml
jobs:
octoguide:
runs-on: ubuntu-latest
steps:
- uses: OctoGuide/bot@0.33.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
rules: |
{
"pr-title-conventional": true
}

Alternatively, switch to the strict config to enable this rule along with every other strict rule:

.github/workflows/octoguide.yml
jobs:
octoguide:
runs-on: ubuntu-latest
steps:
- uses: OctoGuide/bot@0.33.2
with:
config: strict
github-token: ${{ secrets.GITHUB_TOKEN }}

To use this rule on its own, enable it in rules with the none config:

.github/workflows/octoguide.yml
jobs:
octoguide:
runs-on: ubuntu-latest
steps:
- uses: OctoGuide/bot@0.33.2
with:
config: none
github-token: ${{ secrets.GITHUB_TOKEN }}
rules: |
{
"pr-title-conventional": true
}