Skip to content

Commit 7cfb4e5

Browse files
committed
feat(changelog): add support for any commit rule system
1 parent 84471b4 commit 7cfb4e5

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

commitizen/cz/base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
class BaseCommitizen(metaclass=ABCMeta):
1010
bump_pattern: Optional[str] = None
1111
bump_map: Optional[dict] = None
12-
changelog_pattern: Optional[str] = None
13-
changelog_map: Optional[dict] = None
1412
default_style_config: List[Tuple[str, str]] = [
1513
("qmark", "fg:#ff9d00 bold"),
1614
("question", "bold"),
@@ -23,7 +21,13 @@ class BaseCommitizen(metaclass=ABCMeta):
2321
("text", ""),
2422
("disabled", "fg:#858585 italic"),
2523
]
26-
commit_parser: Optional[str] = None
24+
25+
# The whole subject will be parsed as message by default
26+
# This allows supporting changelog for any rule system.
27+
# It can be modified per rule
28+
commit_parser: Optional[str] = r"(?P<message>.*)"
29+
changelog_pattern: Optional[str] = r".*"
30+
changelog_map: Optional[dict] = None # TODO: Use it
2731

2832
def __init__(self, config: BaseConfig):
2933
self.config = config

commitizen/templates/keep_a_changelog_template.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{% for change in changes %}
1212
{% if change.scope %}
1313
- **{{ change.scope }}**: {{ change.message }}
14-
{% else %}
14+
{% elif change.message %}
1515
- {{ change.message }}
1616
{% endif %}
1717
{% endfor %}

tests/commands/test_changelog_command.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ def test_changlog_from_version_zero_point_two(mocker, capsys):
4141

4242

4343
@pytest.mark.usefixtures("tmp_commitizen_project")
44-
def test_changlog_with_unsupported_cz(mocker, capsys):
44+
def test_changlog_with_different_cz(mocker, capsys):
45+
create_file_and_commit("JRA-34 #comment corrected indent issue")
46+
create_file_and_commit("JRA-35 #time 1w 2d 4h 30m Total work logged")
47+
4548
testargs = ["cz", "-n", "cz_jira", "changelog", "--dry-run"]
4649
mocker.patch.object(sys, "argv", testargs)
4750

4851
with pytest.raises(SystemExit):
4952
cli.main()
50-
out, err = capsys.readouterr()
51-
assert "'cz_jira' rule does not support changelog" in err
53+
out, _ = capsys.readouterr()
54+
assert (
55+
out
56+
== "\n## Unreleased \n\n\n- JRA-35 #time 1w 2d 4h 30m Total work logged\n- JRA-34 #comment corrected indent issue\n\n"
57+
)
5258

5359

5460
@pytest.mark.usefixtures("tmp_commitizen_project")

0 commit comments

Comments
 (0)