diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 69031d736d..10d782d30b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -53,7 +53,7 @@ body: - commitizen version: `cz version` - python version: `python --version` - operating system: `python3 -c "import platform; print(platform.system())"` - + ```bash cz version --report ``` diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5c2d68036..c7b0c4a38e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ default_stages: [push] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.1.0 + rev: v4.1.0 hooks: - id: check-vcs-permalinks - id: end-of-file-fixer - exclude: "tests/[test_*|data]/*" + exclude: "tests/[test_*|data|commands/tests_*]/*" - id: trailing-whitespace args: [--markdown-linebreak-ext=md] - id: debug-statements diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 7a6f03a825..994c21c714 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -38,6 +38,18 @@ def __init__(self, config: BaseConfig): if custom_change_type_order: self.change_type_order = custom_change_type_order + commit_parser = self.custom_settings.get("commit_parser") + if commit_parser: + self.commit_parser = commit_parser + + changelog_pattern = self.custom_settings.get("changelog_pattern") + if changelog_pattern: + self.changelog_pattern = changelog_pattern + + change_type_map = self.custom_settings.get("change_type_map") + if change_type_map: + self.change_type_map = change_type_map + def questions(self) -> Questions: return self.custom_settings.get("questions", [{}]) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 3fa7c5256d..0b217bf7f8 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,6 +1,6 @@ import pathlib from collections import OrderedDict -from typing import Any, Iterable, List, MutableMapping, Optional, Tuple, Union +from typing import Any, Dict, Iterable, List, MutableMapping, Optional, Tuple, Union from typing_extensions import TypedDict @@ -20,6 +20,9 @@ class CzSettings(TypedDict, total=False): info_path: Union[str, pathlib.Path] info: str message_template: str + commit_parser: Optional[str] + changelog_pattern: Optional[str] + change_type_map: Optional[Dict[str, str]] class Settings(TypedDict, total=False): diff --git a/docs/auto_check.md b/docs/auto_check.md index 9d746dda50..755f1af8b7 100644 --- a/docs/auto_check.md +++ b/docs/auto_check.md @@ -1,7 +1,7 @@ # Automatically check message before commit ## About -To automatically check a commit message prior to committing, you can use a [git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). +To automatically check a commit message prior to committing, you can use a [git hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). ## How to There are two common methods for installing the hook: @@ -62,4 +62,3 @@ Each time you create a commit, automatically, this hook will analyze it. If the commit message is invalid, it'll be rejected. The commit should follow the given committing rules; otherwise, it won't be accepted. - diff --git a/docs/customization.md b/docs/customization.md index b165638e7c..92610f4585 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -26,6 +26,9 @@ info_path = "cz_customize_info.txt" info = """ This is customized info """ +commit_parser = "^(?Pfeature|bug fix):\\s(?P.*)?" +changelog_pattern = "^(feature|bug fix)?(!)?" +change_type_map = {"feature" = "Feat", "bug fix" = "Fix"} [[tool.commitizen.customize.questions]] type = "list" @@ -66,6 +69,9 @@ The equivalent example for a json config file: "change_type_order": ["BREAKING CHANGE", "feat", "fix", "refactor", "perf"], "info_path": "cz_customize_info.txt", "info": "This is customized info", + "commit_parser": "^(?Pfeature|bug fix):\\s(?P.*)?", + "changelog_pattern": "^(feature|bug fix)?(!)?", + "change_type_map": {"feature": "Feat", "bug fix": "Fix"}, "questions": [ { "type": "list", @@ -109,6 +115,11 @@ commitizen: schema: ": " schema_pattern: "(feature|bug fix):(\\s.*)" bump_pattern: "^(break|new|fix|hotfix)" + commit_parser: "^(?Pfeature|bug fix):\\s(?P.*)?", + changelog_pattern: "^(feature|bug fix)?(!)?", + change_type_map: + feature: Feat + bug fix: Fix bump_map: break: MAJOR new: MINOR @@ -148,8 +159,12 @@ commitizen: | `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) | | `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) | | `change_type_order` | `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "feat", "fix", "refactor", "perf"]` | +| `commit_parser` | `str` | `None` | (OPTIONAL) Regex to extract information used in creating changelog. [See more][changelog-spec] | +| `changelog_pattern` | `str` | `None` | (OPTIONAL) Regex to understand which commits to include in the changelog | +| `change_type_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the type of the commit to a changelog entry | [jinja2]: https://jinja.palletsprojects.com/en/2.10.x/ +[changelog-spec]: https://commitizen-tools.github.io/commitizen/changelog/ #### Detailed `questions` content diff --git a/tests/commands/conftest.py b/tests/commands/conftest.py index 3447b97422..91931849b2 100644 --- a/tests/commands/conftest.py +++ b/tests/commands/conftest.py @@ -3,7 +3,7 @@ import pytest from commitizen import defaults -from commitizen.config import BaseConfig +from commitizen.config import BaseConfig, JsonConfig @pytest.fixture() @@ -13,6 +13,36 @@ def config(): return _config +@pytest.fixture() +def config_customize(): + json_string = r"""{ + "commitizen": { + "name": "cz_customize", + "version": "3.0.0", + "changelog_incremental": "true", + "customize": { + "message_template": "{{prefix}}({{scope}}): {{subject}}\n\n{{body}}{% if is_breaking_change %}\nBREAKING CHANGE: {{footer}}{% endif %}", + "schema": "(): \n\n\n\n(BREAKING CHANGE: