Skip to content

A GitHub Action that ensures that your PR title matches the Conventional Commits spec

License

Notifications You must be signed in to change notification settings

amannn/action-semantic-pull-request

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

action-semantic-pull-request

This is a Github Action that ensures that your PR title matches the Conventional Commits spec.

This is helpful when you're using semantic-release with the Conventional Commits preset. When using the "Squash and merge" strategy, Github will suggest to use the PR title as the commit message. With this action you can validate that the PR title will lead to a correct commit message.

Validation

Examples for valid PR titles:

  • fix: Correct typo.
  • feat: Add support for Node 12.
  • refactor!: Drop support for Node 6.

Note that since PR titles only have a single line, you have to use the ! syntax for breaking changes.

See Conventional Commits for more examples.

Work in progress

Github has support for draft pull requests, which will disable the merge button until the PR is marked as ready for merge.

However, this feature might be disabled for your repository. In this case you can use the special [WIP] prefix to indicate that a pull request is work in progress and isn't ready to be merged. This will avoid the validation of the PR title and the pull request checks remain pending.

Example config

name: "Lint PR"
on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v1.2.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Note the usage of pull_request_target as the event trigger is necessary for a fork-based workflow so the API token is valid for status reporting.