Adding upstream version 0.18.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
9e88905bdf
commit
fe56d9f685
118 changed files with 4146 additions and 2087 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue