1
0
Fork 0

Merging upstream version 4.6.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-08 06:06:34 +02:00
parent f45c9e0d6c
commit 5a71f1c38c
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
16 changed files with 174 additions and 31 deletions

View file

@ -511,8 +511,6 @@ def test_manual_edit(editor, config, mocker: MockFixture, tmp_path):
assert edited_message == test_message.strip()
temp_file.unlink()
@skip_below_py_3_13
def test_commit_command_shows_description_when_use_help_option(

View file

@ -1,13 +1,19 @@
from __future__ import annotations
import os
import re
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional
from typing import Any
from unittest.mock import Mock
import pytest
from jinja2 import FileSystemLoader
from commitizen import changelog, git
from commitizen.changelog_formats import ChangelogFormat
from commitizen.commands.changelog import Changelog
from commitizen.config import BaseConfig
from commitizen.cz.conventional_commits.conventional_commits import (
ConventionalCommitsCz,
)
@ -1499,7 +1505,7 @@ def test_changelog_message_builder_hook_can_access_and_modify_change_type(
def test_render_changelog_with_changelog_release_hook(
gitcommits, tags, any_changelog_format: ChangelogFormat
):
def changelog_release_hook(release: dict, tag: Optional[git.GitTag]) -> dict:
def changelog_release_hook(release: dict, tag: git.GitTag | None) -> dict:
release["extra"] = "whatever"
return release
@ -1631,3 +1637,36 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):
captured = capsys.readouterr()
assert captured.err.count("InvalidVersion") == 2
assert captured.err.count("not-a-version") == 2
def test_changelog_file_name_from_args_and_config():
mock_config = Mock(spec=BaseConfig)
mock_config.path.parent = "/my/project"
mock_config.settings = {
"name": "cz_conventional_commits",
"changelog_file": "CHANGELOG.md",
"encoding": "utf-8",
"changelog_start_rev": "v1.0.0",
"tag_format": "$version",
"legacy_tag_formats": [],
"ignored_tag_formats": [],
"incremental": True,
"changelog_merge_prerelease": True,
}
args = {
"file_name": "CUSTOM.md",
"incremental": None,
"dry_run": False,
"unreleased_version": "1.0.1",
}
changelog = Changelog(mock_config, args)
assert os.path.normpath(changelog.file_name) == os.path.normpath(
os.path.join("/my/project", "CUSTOM.md")
)
args = {"incremental": None, "dry_run": False, "unreleased_version": "1.0.1"}
changelog = Changelog(mock_config, args)
assert os.path.normpath(changelog.file_name) == os.path.normpath(
os.path.join("/my/project", "CHANGELOG.md")
)

View file

@ -0,0 +1,76 @@
import pytest
from commitizen.config import TomlConfig
from commitizen.cz.customize import CustomizeCommitsCz
TOML_WITH_SEARCH_FILTER = r"""
[tool.commitizen]
name = "cz_customize"
[tool.commitizen.customize]
message_template = "{{change_type}}:{% if scope %} ({{scope}}){% endif %}{% if breaking %}!{% endif %} {{message}}"
[[tool.commitizen.customize.questions]]
type = "select"
name = "change_type"
message = "Select the type of change you are committing"
use_search_filter = true
use_jk_keys = false
choices = [
{value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer"},
{value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer"},
{value = "docs", name = "docs: Documentation only changes"},
{value = "style", name = "style: Changes that do not affect the meaning of the code"},
{value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature"},
{value = "perf", name = "perf: A code change that improves performance"},
{value = "test", name = "test: Adding missing or correcting existing tests"},
{value = "build", name = "build: Changes that affect the build system or external dependencies"},
{value = "ci", name = "ci: Changes to CI configuration files and scripts"}
]
[[tool.commitizen.customize.questions]]
type = "input"
name = "scope"
message = "What is the scope of this change? (class or file name): (press [enter] to skip)"
[[tool.commitizen.customize.questions]]
type = "input"
name = "message"
message = "Write a short and imperative summary of the code changes: (lower case and no period)"
"""
@pytest.fixture
def config():
return TomlConfig(data=TOML_WITH_SEARCH_FILTER, path="not_exist.toml")
def test_questions_with_search_filter(config):
"""Test that questions are properly configured with search filter"""
cz = CustomizeCommitsCz(config)
questions = cz.questions()
# Test that the first question (change_type) has search filter enabled
assert questions[0]["type"] == "select"
assert questions[0]["name"] == "change_type"
assert questions[0]["use_search_filter"] is True
assert questions[0]["use_jk_keys"] is False
# Test that the choices are properly configured
choices = questions[0]["choices"]
assert len(choices) == 9 # We have 9 commit types
assert choices[0]["value"] == "fix"
assert choices[1]["value"] == "feat"
def test_message_template(config):
"""Test that the message template is properly configured"""
cz = CustomizeCommitsCz(config)
template = cz.message(
{
"change_type": "feat",
"scope": "search",
"message": "add search filter support",
}
)
assert template == "feat: (search) add search filter support"