From df9615bac55ac6f1c3f516b66279ac0007175030 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 19 Mar 2020 15:00:14 +0100 Subject: Adding upstream version 0.13.1. Signed-off-by: Daniel Baumann --- gitlint/contrib/rules/__init__.py | 0 gitlint/contrib/rules/conventional_commit.py | 39 ++++++++++++++++++++++++++++ gitlint/contrib/rules/signedoff_by.py | 18 +++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 gitlint/contrib/rules/__init__.py create mode 100644 gitlint/contrib/rules/conventional_commit.py create mode 100644 gitlint/contrib/rules/signedoff_by.py (limited to 'gitlint/contrib/rules') diff --git a/gitlint/contrib/rules/__init__.py b/gitlint/contrib/rules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gitlint/contrib/rules/conventional_commit.py b/gitlint/contrib/rules/conventional_commit.py new file mode 100644 index 0000000..3bbbd0f --- /dev/null +++ b/gitlint/contrib/rules/conventional_commit.py @@ -0,0 +1,39 @@ +import re + +from gitlint.options import ListOption +from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation +from gitlint.utils import ustr + +RULE_REGEX = re.compile(r"[^(]+?(\([^)]+?\))?: .+") + + +class ConventionalCommit(LineRule): + """ This rule enforces the spec at https://www.conventionalcommits.org/. """ + + name = "contrib-title-conventional-commits" + id = "CT1" + target = CommitMessageTitle + + options_spec = [ + ListOption( + "types", + ["fix", "feat", "chore", "docs", "style", "refactor", "perf", "test", "revert"], + "Comma separated list of allowed commit types.", + ) + ] + + def validate(self, line, _commit): + violations = [] + + for commit_type in self.options["types"].value: + if line.startswith(ustr(commit_type)): + break + else: + msg = u"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): + msg = u"Title does not follow ConventionalCommits.org format 'type(optional-scope): description'" + violations.append(RuleViolation(self.id, msg, line)) + + return violations diff --git a/gitlint/contrib/rules/signedoff_by.py b/gitlint/contrib/rules/signedoff_by.py new file mode 100644 index 0000000..c2034e7 --- /dev/null +++ b/gitlint/contrib/rules/signedoff_by.py @@ -0,0 +1,18 @@ + +from gitlint.rules import CommitRule, RuleViolation + + +class SignedOffBy(CommitRule): + """ This rule will enforce that each commit body contains a "Signed-Off-By" line. + We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By". + """ + + name = "contrib-body-requires-signed-off-by" + id = "CC1" + + def validate(self, commit): + for line in commit.message.body: + if line.startswith("Signed-Off-By"): + return [] + + return [RuleViolation(self.id, "Body does not contain a 'Signed-Off-By' line", line_nr=1)] -- cgit v1.2.3