scripts: zephyr_commit_rules: improve commit error messages

Make the error messages which appear in CI for invalid commit messages
match the text in the documentation which describes the rules for
commit messages exactly. This hopefully makes it easier for people to
read failing CI results and map them to documentation links describing
what to do instead.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Marti Bolivar 2023-01-27 15:06:48 -08:00
commit 2149d2127a

View file

@ -32,7 +32,7 @@ class BodyMinLineCount(CommitRule):
line_count = len(filtered)
min_line_count = self.options['min-line-count'].value
if line_count < min_line_count:
message = "Commit body has no content, should at least have {} line(s).".format(min_line_count)
message = "Commit message body is empty, should at least have {} line(s).".format(min_line_count)
return [RuleViolation(self.id, message, line_nr=1)]
class BodyMaxLineCount(CommitRule):
@ -49,7 +49,7 @@ class BodyMaxLineCount(CommitRule):
line_count = len(commit.message.body)
max_line_count = self.options['max-line-count'].value
if line_count > max_line_count:
message = "Commit body contains too many lines ({0} > {1})".format(line_count, max_line_count)
message = "Commit message body contains too many lines ({0} > {1})".format(line_count, max_line_count)
return [RuleViolation(self.id, message, line_nr=1)]
class SignedOffBy(CommitRule):
@ -72,7 +72,7 @@ class SignedOffBy(CommitRule):
return [RuleViolation(self.id, "Signed-off-by: must have a full name", line_nr=1)]
else:
return
return [RuleViolation(self.id, "Commit body does not contain a 'Signed-off-by:' line", line_nr=1)]
return [RuleViolation(self.id, "Commit message does not contain a 'Signed-off-by:' line", line_nr=1)]
class TitleMaxLengthRevert(LineRule):
name = "title-max-length-no-revert"
@ -104,7 +104,7 @@ class MaxLineLengthExceptions(LineRule):
id = "UC4"
target = CommitMessageBody
options_spec = [IntOption('line-length', 80, "Max line length")]
violation_message = "Commit body line exceeds max length ({0}>{1})"
violation_message = "Commit message body line exceeds max length ({0}>{1})"
def validate(self, line, _commit):
max_length = self.options['line-length'].value
@ -128,5 +128,5 @@ class BodyContainsBlockedTags(LineRule):
flags = re.IGNORECASE
for tag in self.tags:
if re.search(rf"^\s*{tag}:", line, flags=flags):
return [RuleViolation(self.id, f"Commit body contains a blocked tag: {tag}")]
return [RuleViolation(self.id, f"Commit message contains a blocked tag: {tag}")]
return