summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/contrib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-19 14:52:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-19 14:52:46 +0000
commita2aa51f5702b18016c25d943499941323952704d (patch)
tree7ee43f79639ee53903e7ca389e548974e1497c3a /gitlint-core/gitlint/contrib
parentAdding upstream version 0.17.0. (diff)
downloadgitlint-a2aa51f5702b18016c25d943499941323952704d.tar.xz
gitlint-a2aa51f5702b18016c25d943499941323952704d.zip
Adding upstream version 0.18.0.upstream/0.18.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint-core/gitlint/contrib')
-rw-r--r--gitlint-core/gitlint/contrib/rules/authors_commit.py46
-rw-r--r--gitlint-core/gitlint/contrib/rules/conventional_commit.py4
-rw-r--r--gitlint-core/gitlint/contrib/rules/disallow_cleanup_commits.py22
-rw-r--r--gitlint-core/gitlint/contrib/rules/signedoff_by.py3
4 files changed, 71 insertions, 4 deletions
diff --git a/gitlint-core/gitlint/contrib/rules/authors_commit.py b/gitlint-core/gitlint/contrib/rules/authors_commit.py
new file mode 100644
index 0000000..ce11663
--- /dev/null
+++ b/gitlint-core/gitlint/contrib/rules/authors_commit.py
@@ -0,0 +1,46 @@
+import re
+from pathlib import Path
+from typing import Tuple
+
+
+from gitlint.rules import CommitRule, RuleViolation
+
+
+class AllowedAuthors(CommitRule):
+ """Enforce that only authors listed in the AUTHORS file are allowed to commit."""
+
+ authors_file_names = ("AUTHORS", "AUTHORS.txt", "AUTHORS.md")
+ parse_authors = re.compile(r"^(?P<name>.*) <(?P<email>.*)>$", re.MULTILINE)
+
+ name = "contrib-allowed-authors"
+
+ id = "CC3"
+
+ @classmethod
+ def _read_authors_from_file(cls, git_ctx) -> Tuple[str, str]:
+ for file_name in cls.authors_file_names:
+ path = Path(git_ctx.repository_path) / file_name
+ if path.exists():
+ authors_file = path
+ break
+ else:
+ raise FileNotFoundError("No AUTHORS file found!")
+
+ authors_file_content = authors_file.read_text("utf-8")
+ authors = re.findall(cls.parse_authors, authors_file_content)
+
+ return set(authors), authors_file.name
+
+ def validate(self, commit):
+ registered_authors, authors_file_name = AllowedAuthors._read_authors_from_file(commit.message.context)
+
+ author = (commit.author_name, commit.author_email.lower())
+
+ if author not in registered_authors:
+ return [
+ RuleViolation(
+ self.id,
+ f"Author not in '{authors_file_name}' file: " f'"{commit.author_name} <{commit.author_email}>"',
+ )
+ ]
+ return []
diff --git a/gitlint-core/gitlint/contrib/rules/conventional_commit.py b/gitlint-core/gitlint/contrib/rules/conventional_commit.py
index 9c9d5cb..705b083 100644
--- a/gitlint-core/gitlint/contrib/rules/conventional_commit.py
+++ b/gitlint-core/gitlint/contrib/rules/conventional_commit.py
@@ -7,7 +7,7 @@ RULE_REGEX = re.compile(r"([^(]+?)(\([^)]+?\))?!?: .+")
class ConventionalCommit(LineRule):
- """ This rule enforces the spec at https://www.conventionalcommits.org/. """
+ """This rule enforces the spec at https://www.conventionalcommits.org/."""
name = "contrib-title-conventional-commits"
id = "CT1"
@@ -31,7 +31,7 @@ class ConventionalCommit(LineRule):
else:
line_commit_type = match.group(1)
if line_commit_type not in self.options["types"].value:
- opt_str = ', '.join(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
diff --git a/gitlint-core/gitlint/contrib/rules/disallow_cleanup_commits.py b/gitlint-core/gitlint/contrib/rules/disallow_cleanup_commits.py
new file mode 100644
index 0000000..7f62dee
--- /dev/null
+++ b/gitlint-core/gitlint/contrib/rules/disallow_cleanup_commits.py
@@ -0,0 +1,22 @@
+from gitlint.rules import CommitRule, RuleViolation
+
+
+class DisallowCleanupCommits(CommitRule):
+ """This rule checks the commits for "fixup!"/"squash!"/"amend!" commits
+ and rejects them.
+ """
+
+ name = "contrib-disallow-cleanup-commits"
+ id = "CC2"
+
+ def validate(self, commit):
+ if commit.is_fixup_commit:
+ return [RuleViolation(self.id, "Fixup commits are not allowed", line_nr=1)]
+
+ if commit.is_squash_commit:
+ return [RuleViolation(self.id, "Squash commits are not allowed", line_nr=1)]
+
+ if commit.is_fixup_amend_commit:
+ return [RuleViolation(self.id, "Amend commits are not allowed", line_nr=1)]
+
+ return []
diff --git a/gitlint-core/gitlint/contrib/rules/signedoff_by.py b/gitlint-core/gitlint/contrib/rules/signedoff_by.py
index 139a1b1..5ea8217 100644
--- a/gitlint-core/gitlint/contrib/rules/signedoff_by.py
+++ b/gitlint-core/gitlint/contrib/rules/signedoff_by.py
@@ -1,9 +1,8 @@
-
from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
- """ This rule will enforce that each commit body contains a "Signed-off-by" line.
+ """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".
"""