Last active
March 27, 2025 13:58
-
-
Save neiser/06e1f2237c2786c6dfeda3a3101afb16 to your computer and use it in GitHub Desktop.
Conventional Commit Regex for GitLab Push Rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The regex is split into a YAML sequence for better commenting | |
# Use | |
# yq 'join("")' conventional-commit-regex.yml | |
# to get the actual regex string! | |
# Test changes using | |
# https://regex101.com/r/tl6h3n/6 (please update this if you make some changes below) | |
# See also https://docs.gitlab.com/user/project/repository/push_rules/#validate-commit-messages | |
# In particular, note that GitLab uses multiline mode by default, so use \A, \z instead of ^ or $ | |
# The regex also uses 'named matching groups' for better inline structuring. | |
# match start of string (even in multiline mode, ^ does not work as multiline mode is on) | |
# semantic-release pushes notes with this commit message beginning, see https://gitlab.com/gitlab-org/gitlab/-/issues/207807 | |
- \A(?:Notes added by 'git notes add'| # <1> | |
# Allow markers fixup! and squash!, should only be pushed on feature branches though | |
- (?P<marker>fixup! |squash! )? | |
# Groups 'type', 'scope' (optional), 'breaking' (optional) as required by https://www.conventionalcommits.org/en/v1.0.0/ | |
# Must end with characters colon then space. | |
# We use a trick space '[ ]' to have a space as a trailing character. | |
# This trick also makes this as a YAML string node and not a YAML map node. | |
- (?P<type>feat|fix|ci|chore|docs|test|style|refactor|build|perf|revert)(?:\((?P<scope>[-\w]+)\))?(?P<breaking>!)?:[ ] | |
# Group 'description' may contain punctuation, but must not end with | |
- (?P<description>.+?[^:,\.\n]) | |
# Either single line commit message with optional trailing \n | |
# or commit body with at least 3 arbitrary characters | |
- (?P<endOrBody>\n?\z|\n\n.{3,}) | |
# Closing the first alternative, opened in <1> | |
- ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment