summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-19 14:52:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-11-19 14:53:01 +0000
commitf3b6c222fb11c96e2f8bbaa0622f46c8ec486874 (patch)
tree0f38497775e27d3e16b20573b36dd22aa5b24f3e /examples
parentReleasing debian version 0.17.0-1. (diff)
downloadgitlint-f3b6c222fb11c96e2f8bbaa0622f46c8ec486874.tar.xz
gitlint-f3b6c222fb11c96e2f8bbaa0622f46c8ec486874.zip
Merging upstream version 0.18.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/my_commit_rules.py16
-rw-r--r--examples/my_configuration_rules.py7
-rw-r--r--examples/my_line_rules.py17
3 files changed, 19 insertions, 21 deletions
diff --git a/examples/my_commit_rules.py b/examples/my_commit_rules.py
index 2805501..35bb836 100644
--- a/examples/my_commit_rules.py
+++ b/examples/my_commit_rules.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from gitlint.rules import CommitRule, RuleViolation
from gitlint.options import IntOption, ListOption
@@ -27,20 +25,20 @@ class BodyMaxLineCount(CommitRule):
id = "UC1"
# A rule MAY have an option_spec if its behavior should be configurable.
- options_spec = [IntOption('max-line-count', 3, "Maximum body line count")]
+ options_spec = [IntOption("max-line-count", 3, "Maximum body line count")]
def validate(self, commit):
self.log.debug("BodyMaxLineCount: This will be visible when running `gitlint --debug`")
line_count = len(commit.message.body)
- max_line_count = self.options['max-line-count'].value
+ max_line_count = self.options["max-line-count"].value
if line_count > max_line_count:
message = f"Body contains too many lines ({line_count} > {max_line_count})"
return [RuleViolation(self.id, message, line_nr=1)]
class SignedOffBy(CommitRule):
- """ This rule will enforce that each commit contains a "Signed-off-by" line.
+ """This rule will enforce that each commit 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".
"""
@@ -61,8 +59,8 @@ class SignedOffBy(CommitRule):
class BranchNamingConventions(CommitRule):
- """ This rule will enforce that a commit is part of a branch that meets certain naming conventions.
- See GitFlow for real-world example of this: https://nvie.com/posts/a-successful-git-branching-model/
+ """This rule will enforce that a commit is part of a branch that meets certain naming conventions.
+ See GitFlow for real-world example of this: https://nvie.com/posts/a-successful-git-branching-model/
"""
# A rule MUST have a human friendly name
@@ -72,13 +70,13 @@ class BranchNamingConventions(CommitRule):
id = "UC3"
# A rule MAY have an option_spec if its behavior should be configurable.
- options_spec = [ListOption('branch-prefixes', ["feature/", "hotfix/", "release/"], "Allowed branch prefixes")]
+ options_spec = [ListOption("branch-prefixes", ["feature/", "hotfix/", "release/"], "Allowed branch prefixes")]
def validate(self, commit):
self.log.debug("BranchNamingConventions: This line will be visible when running `gitlint --debug`")
violations = []
- allowed_branch_prefixes = self.options['branch-prefixes'].value
+ allowed_branch_prefixes = self.options["branch-prefixes"].value
for branch in commit.branches:
valid_branch_name = False
diff --git a/examples/my_configuration_rules.py b/examples/my_configuration_rules.py
index 7c00707..7715c0b 100644
--- a/examples/my_configuration_rules.py
+++ b/examples/my_configuration_rules.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from gitlint.rules import ConfigurationRule
from gitlint.options import IntOption
@@ -36,7 +34,7 @@ class ReleaseConfigurationRule(ConfigurationRule):
id = "UCR1"
# A rule MAY have an option_spec if its behavior should be configurable.
- options_spec = [IntOption('custom-verbosity', 2, "Gitlint verbosity for release commits")]
+ options_spec = [IntOption("custom-verbosity", 2, "Gitlint verbosity for release commits")]
def apply(self, config, commit):
self.log.debug("ReleaseConfigurationRule: This will be visible when running `gitlint --debug`")
@@ -44,7 +42,6 @@ class ReleaseConfigurationRule(ConfigurationRule):
# If the commit title starts with 'Release', we want to modify
# how all subsequent rules interpret that commit
if commit.message.title.startswith("Release"):
-
# If your Release commit messages are auto-generated, the
# body might contain trailing whitespace. Let's ignore that
config.ignore.append("body-trailing-whitespace")
@@ -60,7 +57,7 @@ class ReleaseConfigurationRule(ConfigurationRule):
# config.set_general_option(<general-option>, <value>)
config.set_general_option("verbosity", 2)
# Wwe can also use custom options to make this configurable
- config.set_general_option("verbosity", self.options['custom-verbosity'].value)
+ config.set_general_option("verbosity", self.options["custom-verbosity"].value)
# Strip any lines starting with $ from the commit message
# (this only affects how gitlint sees your commit message, it does
diff --git a/examples/my_line_rules.py b/examples/my_line_rules.py
index 3a1ef36..58b0108 100644
--- a/examples/my_line_rules.py
+++ b/examples/my_line_rules.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
from gitlint.options import ListOption
@@ -21,8 +19,8 @@ that fits your needs.
class SpecialChars(LineRule):
- """ This rule will enforce that the commit message title does not contain any of the following characters:
- $^%@!*() """
+ """This rule will enforce that the commit message title does not contain any of the following characters:
+ $^%@!*()"""
# A rule MUST have a human friendly name
name = "title-no-special-chars"
@@ -35,15 +33,20 @@ class SpecialChars(LineRule):
target = CommitMessageTitle
# A rule MAY have an option_spec if its behavior should be configurable.
- options_spec = [ListOption('special-chars', ['$', '^', '%', '@', '!', '*', '(', ')'],
- "Comma separated list of characters that should not occur in the title")]
+ options_spec = [
+ ListOption(
+ "special-chars",
+ ["$", "^", "%", "@", "!", "*", "(", ")"],
+ "Comma separated list of characters that should not occur in the title",
+ )
+ ]
def validate(self, line, _commit):
self.log.debug("SpecialChars: This will be visible when running `gitlint --debug`")
violations = []
# options can be accessed by looking them up by their name in self.options
- for char in self.options['special-chars'].value:
+ for char in self.options["special-chars"].value:
if char in line:
msg = f"Title contains the special character '{char}'"
violation = RuleViolation(self.id, msg, line)