Regex to validate the commit message #173

Open
opened 2026-02-17 11:51:29 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @JobaDiniz on GitHub (Apr 28, 2023).

I did not know there was a conventional commit org! I was using my own conventional very similar borrowed from years ago somewhere.

Is there a regex that we can to check the commit message pattern following the conventional rules?

For example, I have this github action which uses gsactions/commit-message-checker@v2.

name: commit

on:
  pull_request:
    branches: [ develop ]

jobs:
  check-commit-message:
    name: check commit message
    runs-on: ubuntu-latest
    steps:
    - name: Check message against regex
      uses: gsactions/commit-message-checker@v2
      with:
        pattern: '(?:build|docs|refactor|test|fix|perf|chore|feat)(?:\(\w+\))?:\s[a-z]{1,2}.+'
        error: "The commit message must follow the commit messages guidelines"
        excludeDescription: 'true' # optional: this excludes the description body of a pull request
        excludeTitle: 'true' # optional: this excludes the title of a pull request
        checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request
        accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true
Originally created by @JobaDiniz on GitHub (Apr 28, 2023). I did not know there was a conventional commit org! I was using my own conventional very similar borrowed from years ago somewhere. Is there a regex that we can to check the commit message pattern following the conventional rules? For example, I have this github action which uses [gsactions/commit-message-checker@v2](https://github.com/marketplace/actions/gs-commit-message-checker). ```yml name: commit on: pull_request: branches: [ develop ] jobs: check-commit-message: name: check commit message runs-on: ubuntu-latest steps: - name: Check message against regex uses: gsactions/commit-message-checker@v2 with: pattern: '(?:build|docs|refactor|test|fix|perf|chore|feat)(?:\(\w+\))?:\s[a-z]{1,2}.+' error: "The commit message must follow the commit messages guidelines" excludeDescription: 'true' # optional: this excludes the description body of a pull request excludeTitle: 'true' # optional: this excludes the title of a pull request checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true ```
Author
Owner

@damianopetrungaro commented on GitHub (Apr 29, 2023):

Hey! There is this GitHub action I use often: https://github.com/webiny/action-conventional-commits

Do you think would that work for your use case?

@damianopetrungaro commented on GitHub (Apr 29, 2023): Hey! There is this GitHub action I use often: https://github.com/webiny/action-conventional-commits Do you think would that work for your use case?
Author
Owner

@JobaDiniz commented on GitHub (Apr 29, 2023):

That's even better!

@JobaDiniz commented on GitHub (Apr 29, 2023): That's even better!
Author
Owner

@thekaveman commented on GitHub (Aug 14, 2023):

There's also a pre-commit hook you can add for validating commit messages at commit time: https://github.com/compilerla/conventional-pre-commit

Disclaimer: My company is the author of this hook.

@thekaveman commented on GitHub (Aug 14, 2023): There's also a `pre-commit` hook you can add for validating commit messages at commit time: https://github.com/compilerla/conventional-pre-commit _Disclaimer: My company is the author of this hook._
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/conventionalcommits.org#173