Regex to validate the commit message
JobaDiniz opened this issue · comments
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
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?
That's even better!
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.