summaryrefslogtreecommitdiffstats
path: root/qa/samples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:07:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-11-03 06:07:48 +0000
commit85812cd25d9e2f015bb71b26d51458b3718bf6c7 (patch)
tree463ad57ffbe3636e06e9bb36104fbf12938e78c1 /qa/samples
parentReleasing debian version 0.13.1-6. (diff)
downloadgitlint-85812cd25d9e2f015bb71b26d51458b3718bf6c7.tar.xz
gitlint-85812cd25d9e2f015bb71b26d51458b3718bf6c7.zip
Merging upstream version 0.14.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/samples')
-rw-r--r--qa/samples/config/contrib-enabled0
-rw-r--r--qa/samples/config/named-rules8
-rw-r--r--qa/samples/config/named-user-rules15
-rw-r--r--qa/samples/user_rules/extra/extra_rules.py52
4 files changed, 69 insertions, 6 deletions
diff --git a/qa/samples/config/contrib-enabled b/qa/samples/config/contrib-enabled
deleted file mode 100644
index e69de29..0000000
--- a/qa/samples/config/contrib-enabled
+++ /dev/null
diff --git a/qa/samples/config/named-rules b/qa/samples/config/named-rules
new file mode 100644
index 0000000..f9bbdf5
--- /dev/null
+++ b/qa/samples/config/named-rules
@@ -0,0 +1,8 @@
+[title-must-not-contain-word]
+words=WIP,thåt
+
+[title-must-not-contain-word:extra-wôrds]
+words=hûr,dûr
+
+[title-must-not-contain-word: even$more%wôrds ]
+words=fôo,bår \ No newline at end of file
diff --git a/qa/samples/config/named-user-rules b/qa/samples/config/named-user-rules
new file mode 100644
index 0000000..ed811fb
--- /dev/null
+++ b/qa/samples/config/named-user-rules
@@ -0,0 +1,15 @@
+# Ignore other user-defined rules
+[general]
+ignore=UC1,UC2,UC3,configürable:ignöred
+
+[UC4:föo]
+int-öption=3
+str-öption=föo
+
+[configürable:bår]
+str-öption=bår
+list-öption=bar,list
+
+# The following rule will be ignored
+[configürable:ignöred]
+str-öption=foöbar \ No newline at end of file
diff --git a/qa/samples/user_rules/extra/extra_rules.py b/qa/samples/user_rules/extra/extra_rules.py
index 8109299..6fb985f 100644
--- a/qa/samples/user_rules/extra/extra_rules.py
+++ b/qa/samples/user_rules/extra/extra_rules.py
@@ -1,16 +1,19 @@
-from gitlint.rules import CommitRule, RuleViolation
+# -*- coding: utf-8 -*-
+
+from gitlint.rules import CommitRule, RuleViolation, ConfigurationRule
+from gitlint.options import IntOption, StrOption, ListOption
from gitlint.utils import sstr
class GitContextRule(CommitRule):
""" Rule that tests whether we can correctly access certain gitcontext properties """
- name = "gitcontext"
+ name = u"gïtcontext"
id = "UC1"
def validate(self, commit):
violations = [
- RuleViolation(self.id, "GitContext.current_branch: {0}".format(commit.context.current_branch), line_nr=1),
- RuleViolation(self.id, "GitContext.commentchar: {0}".format(commit.context.commentchar), line_nr=1)
+ RuleViolation(self.id, u"GitContext.current_branch: {0}".format(commit.context.current_branch), line_nr=1),
+ RuleViolation(self.id, u"GitContext.commentchar: {0}".format(commit.context.commentchar), line_nr=1)
]
return violations
@@ -18,12 +21,49 @@ class GitContextRule(CommitRule):
class GitCommitRule(CommitRule):
""" Rule that tests whether we can correctly access certain commit properties """
- name = "gitcommit"
+ name = u"gïtcommit"
id = "UC2"
def validate(self, commit):
violations = [
- RuleViolation(self.id, "GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1),
+ RuleViolation(self.id, u"GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1),
+ RuleViolation(self.id, u"GitCommit.custom_prop: {0}".format(commit.custom_prop), line_nr=1),
+ ]
+
+ return violations
+
+
+class GitlintConfigurationRule(ConfigurationRule):
+ """ Rule that tests whether we can correctly access the config as well as modify the commit message """
+ name = u"cönfigrule"
+ id = "UC3"
+
+ def apply(self, config, commit):
+ # We add a line to the commit message body that pulls a value from config, this proves we can modify the body
+ # and read the config contents
+ commit.message.body.append("{0} ".format(config.target)) # trailing whitespace deliberate to trigger violation
+
+ # We set a custom property that we access in CommitRule, to prove we can add extra properties to the commit
+ commit.custom_prop = u"foöbar"
+
+ # We also ignore some extra rules, proving that we can modify the config
+ config.ignore.append("B4")
+
+
+class ConfigurableCommitRule(CommitRule):
+ """ Rule that tests that we can add configuration to user-defined rules """
+ name = u"configürable"
+ id = "UC4"
+
+ options_spec = [IntOption(u"int-öption", 2, u"int-öption description"),
+ StrOption(u"str-öption", u"föo", u"int-öption description"),
+ ListOption(u"list-öption", [u"foo", u"bar"], u"list-öption description")]
+
+ def validate(self, _):
+ violations = [
+ RuleViolation(self.id, u"int-öption: {0}".format(self.options[u'int-öption'].value), line_nr=1),
+ RuleViolation(self.id, u"str-öption: {0}".format(self.options[u'str-öption'].value), line_nr=1),
+ RuleViolation(self.id, u"list-öption: {0}".format(sstr(self.options[u'list-öption'].value)), line_nr=1),
]
return violations