|
1 | 1 | import os
|
2 | 2 | import re
|
3 | 3 | import sys
|
4 |
| -from typing import Any, Dict, Optional |
| 4 | +from typing import Any, Dict, List, Optional |
5 | 5 |
|
6 | 6 | from commitizen import factory, git, out
|
7 | 7 | from commitizen.config import BaseConfig
|
@@ -30,6 +30,15 @@ def __init__(self, config: BaseConfig, arguments: Dict[str, Any], cwd=os.getcwd(
|
30 | 30 | arguments.get("allow_abort", config.settings["allow_abort"])
|
31 | 31 | )
|
32 | 32 |
|
| 33 | + # we need to distinguish between None and [], which is a valid value |
| 34 | + |
| 35 | + allowed_prefixes = arguments.get("allowed_prefixes") |
| 36 | + self.allowed_prefixes: List[str] = ( |
| 37 | + allowed_prefixes |
| 38 | + if allowed_prefixes is not None |
| 39 | + else config.settings["allowed_prefixes"] |
| 40 | + ) |
| 41 | + |
33 | 42 | self._valid_command_argument()
|
34 | 43 |
|
35 | 44 | self.config: BaseConfig = config
|
@@ -132,12 +141,7 @@ def _filter_comments(msg: str) -> str:
|
132 | 141 | def validate_commit_message(self, commit_msg: str, pattern: str) -> bool:
|
133 | 142 | if not commit_msg:
|
134 | 143 | return self.allow_abort
|
135 |
| - if ( |
136 |
| - commit_msg.startswith("Merge") |
137 |
| - or commit_msg.startswith("Revert") |
138 |
| - or commit_msg.startswith("Pull request") |
139 |
| - or commit_msg.startswith("fixup!") |
140 |
| - or commit_msg.startswith("squash!") |
141 |
| - ): |
| 144 | + |
| 145 | + if any(map(commit_msg.startswith, self.allowed_prefixes)): |
142 | 146 | return True
|
143 | 147 | return bool(re.match(pattern, commit_msg))
|
0 commit comments