Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(changelog): add incremental parameter to changelog generation #1808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bearomorphism wants to merge 1 commit into master
base: master
Choose a base branch
Loading
from fix-1620
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commitizen/commands/changelog.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def __call__(self) -> None:
tree,
self.cz.template_loader,
self.template,
incremental=self.incremental, # extra variable for the template
**{
**self.cz.template_extras,
**self.config.settings["extras"],
Expand Down
54 changes: 54 additions & 0 deletions tests/commands/test_changelog_command.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1728,3 +1728,57 @@ class FakeTemplate:

assert not target.exists()
assert "Template filename is not set" in str(exc_info.value)


def test_changelog_template_incremental_variable(
tmp_commitizen_project: Path,
any_changelog_format: ChangelogFormat,
util: UtilFixture,
file_regression: FileRegressionFixture,
):
"""
Test that the changelog template is not rendered when the incremental flag is not set.
Reference: https://github.com/commitizen-tools/commitizen/discussions/1620
"""
project_root = Path(tmp_commitizen_project)
changelog_tpl = project_root / any_changelog_format.template
changelog_tpl.write_text(
dedent("""
{% if not incremental %}
# CHANGELOG
{% endif %}

{% for entry in tree %}

## {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}

{% for change_key, changes in entry.changes.items() %}

{% if change_key %}
### {{ change_key }}
{% endif %}

{% for change in changes %}
{% if change.scope %}
- **{{ change.scope }}**: {{ change.message }}
{% elif change.message %}
- {{ change.message }}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
""")
)
target = "CHANGELOG.md"

util.create_file_and_commit("feat(foo): new file")
util.run_cli("changelog", "--file-name", target)
with open(target, encoding="utf-8") as f:
out = f.read()
file_regression.check(out, extension=".md")

util.create_file_and_commit("refactor(bar): another new file")
util.run_cli("changelog", "--file-name", target, "--incremental")
with open(target, encoding="utf-8") as f:
out = f.read()
file_regression.check(out, extension=".incremental.md")
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG


## Unreleased

### Feat

- **foo**: new file

### Refactor

- **bar**: another new file
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CHANGELOG


## Unreleased

### Feat

- **foo**: new file

AltStyle によって変換されたページ (->オリジナル) /