| 1 |
from gitlint.options import IntOption, ListOption, StrOption |
| 2 |
from gitlint.rules import CommitRule, ConfigurationRule, RuleViolation |
| 3 |
|
| 4 |
|
| 5 |
class GitContextRule(CommitRule): |
| 6 |
"""Rule that tests whether we can correctly access certain gitcontext properties""" |
| 7 |
|
| 8 |
name = "gïtcontext" |
| 9 |
id = "UC1" |
| 10 |
|
| 11 |
def validate(self, commit): |
| 12 |
violations = [ |
| 13 |
RuleViolation(self.id, f"GitContext.current_branch: {commit.context.current_branch}", line_nr=1), |
| 14 |
RuleViolation(self.id, f"GitContext.commentchar: {commit.context.commentchar}", line_nr=1), |
| 15 |
] |
| 16 |
|
| 17 |
return violations |
| 18 |
|
| 19 |
|
| 20 |
class GitCommitRule(CommitRule): |
| 21 |
"""Rule that tests whether we can correctly access certain commit properties""" |
| 22 |
|
| 23 |
name = "gïtcommit" |
| 24 |
id = "UC2" |
| 25 |
|
| 26 |
def validate(self, commit): |
| 27 |
violations = [ |
| 28 |
RuleViolation(self.id, f"GitCommit.branches: {commit.branches}", line_nr=1), |
| 29 |
RuleViolation(self.id, f"GitCommit.custom_prop: {commit.custom_prop}", line_nr=1), |
| 30 |
] |
| 31 |
|
| 32 |
return violations |
| 33 |
|
| 34 |
|
| 35 |
class GitlintConfigurationRule(ConfigurationRule): |
| 36 |
"""Rule that tests whether we can correctly access the config as well as modify the commit message""" |
| 37 |
|
| 38 |
name = "cönfigrule" |
| 39 |
id = "UC3" |
| 40 |
|
| 41 |
def apply(self, config, commit): |
| 42 |
|
| 43 |
|
| 44 |
commit.message.body.append(f"{config.target} ") |
| 45 |
|
| 46 |
|
| 47 |
commit.custom_prop = "foöbar" |
| 48 |
|
| 49 |
|
| 50 |
config.ignore.append("B4") |
| 51 |
|
| 52 |
|
| 53 |
class ConfigurableCommitRule(CommitRule): |
| 54 |
"""Rule that tests that we can add configuration to user-defined rules""" |
| 55 |
|
| 56 |
name = "configürable" |
| 57 |
id = "UC4" |
| 58 |
|
| 59 |
options_spec = [ |
| 60 |
IntOption("int-öption", 2, "int-öption description"), |
| 61 |
StrOption("str-öption", "föo", "int-öption description"), |
| 62 |
ListOption("list-öption", ["foo", "bar"], "list-öption description"), |
| 63 |
] |
| 64 |
|
| 65 |
def validate(self, _): |
| 66 |
violations = [ |
| 67 |
RuleViolation(self.id, f"int-öption: {self.options['int-öption'].value}", line_nr=1), |
| 68 |
RuleViolation(self.id, f"str-öption: {self.options['str-öption'].value}", line_nr=1), |
| 69 |
RuleViolation(self.id, f"list-öption: {self.options['list-öption'].value}", line_nr=1), |
| 70 |
] |
| 71 |
|
| 72 |
return violations |