diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
commit | b8d423e7d13686d6627571d6c4adf12661d82147 (patch) | |
tree | 11d64ff26fb53c3c01ee35d062ca0c51fb883550 /gitlint/contrib/rules/conventional_commit.py | |
parent | Adding upstream version 0.15.1. (diff) | |
download | gitlint-7f9eae8e5939f911ce10870f5e2caaae6d546b7f.tar.xz gitlint-7f9eae8e5939f911ce10870f5e2caaae6d546b7f.zip |
Adding upstream version 0.16.0.upstream/0.16.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint/contrib/rules/conventional_commit.py')
-rw-r--r-- | gitlint/contrib/rules/conventional_commit.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/gitlint/contrib/rules/conventional_commit.py b/gitlint/contrib/rules/conventional_commit.py index 71f6adf..9c9d5cb 100644 --- a/gitlint/contrib/rules/conventional_commit.py +++ b/gitlint/contrib/rules/conventional_commit.py @@ -3,7 +3,7 @@ import re from gitlint.options import ListOption from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation -RULE_REGEX = re.compile(r"[^(]+?(\([^)]+?\))?: .+") +RULE_REGEX = re.compile(r"([^(]+?)(\([^)]+?\))?!?: .+") class ConventionalCommit(LineRule): @@ -23,16 +23,15 @@ class ConventionalCommit(LineRule): def validate(self, line, _commit): violations = [] + match = RULE_REGEX.match(line) - for commit_type in self.options["types"].value: - if line.startswith(commit_type): - break - else: - msg = "Title does not start with one of {0}".format(', '.join(self.options['types'].value)) - violations.append(RuleViolation(self.id, msg, line)) - - if not RULE_REGEX.match(line): + if not match: msg = "Title does not follow ConventionalCommits.org format 'type(optional-scope): description'" violations.append(RuleViolation(self.id, msg, line)) + else: + line_commit_type = match.group(1) + if line_commit_type not in self.options["types"].value: + opt_str = ', '.join(self.options['types'].value) + violations.append(RuleViolation(self.id, f"Title does not start with one of {opt_str}", line)) return violations |