github.com/redhat-appstudio/release-service@v0.0.0-20240507143925-083712697924/.github/gitlint/contrib_format_conventional_commits.py (about) 1 # -*- coding: utf-8 -*- 2 from gitlint.rules import CommitRule, RuleViolation 3 import re 4 5 6 class ConventionalCommitsFormat(CommitRule): 7 """This rule will enforce that each commit title follows the 8 conventional commit prefix standards and the commit 9 description starts with a lowercase character.""" 10 11 id = "UC1" 12 name = "contrib-format-conventional-commits" 13 14 def validate(self, commit): 15 """Validate the given commit checking that the title has a 16 proper prefix and the description starts with a lowercase.""" 17 18 regex_string = "^(chore|docs|feat|fix|refactor|style|test|revert)(\(.*\))?: [a-z].*$" 19 pattern = re.compile(regex_string) 20 if not pattern.match(commit.message.title): 21 return [ 22 RuleViolation( 23 self.id, f"Commit title doesn't follow the spec {regex_string}", line_nr=1 24 ) 25 ]