Skip to content
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

Simple configuration for Keep a Changelog style changelogs #693

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,16 @@ If you use this way to configure custom fragment types, ensure there is no ``too
Each table within this array has the following mandatory keys:


``directory``
The type / category of the fragment.

``name``
``name`` (required)
The description of the fragment type, as it must be included
in the news file.

``showcontent``
``directory`` (optional)
The type / category of the fragment.

Defaults to ``name.lower()``.

``showcontent`` (optional)
A boolean value indicating whether the fragment contents should be included in the news file.

``true`` by default.
Expand All @@ -305,7 +307,7 @@ Each table within this array has the following mandatory keys:
Orphan fragments (those without an issue number) always have their content included.
If a fragment was created, it means that information is important for end users.

``check``
``check`` (optional)
A boolean value indicating whether the fragment should be considered by the ``towncrier check`` command.

``true`` by default.
Expand All @@ -316,9 +318,7 @@ For example:

[tool.towncrier]
[[tool.towncrier.type]]
directory = "deprecation"
name = "Deprecations"
showcontent = true

[[tool.towncrier.type]]
directory = "chore"
Expand Down
12 changes: 0 additions & 12 deletions docs/markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,22 @@ Put the following into your ``pyproject.toml`` or ``towncrier.toml``:
issue_format = "[#{issue}](https://github.com/twisted/my-project/issues/{issue})"
[[tool.towncrier.type]]
directory = "security"
name = "Security"
showcontent = true
[[tool.towncrier.type]]
directory = "removed"
name = "Removed"
showcontent = true
[[tool.towncrier.type]]
directory = "deprecated"
name = "Deprecated"
showcontent = true
[[tool.towncrier.type]]
directory = "added"
name = "Added"
showcontent = true
[[tool.towncrier.type]]
directory = "changed"
name = "Changed"
showcontent = true
[[tool.towncrier.type]]
directory = "fixed"
name = "Fixed"
showcontent = true
Expand Down
4 changes: 2 additions & 2 deletions src/towncrier/_settings/fragment_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def load(self) -> Mapping[str, Mapping[str, Any]]:
types = {}
types_config = self.config["type"]
for type_config in types_config:
directory = type_config["directory"]
fragment_type_name = type_config["name"]
is_content_required = type_config["showcontent"]
directory = type_config.get("directory", fragment_type_name.lower())
is_content_required = type_config.get("showcontent", True)
check = type_config.get("check", True)
types[directory] = {
"name": fragment_type_name,
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/691.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
More simple configuration for Keep a Changelog style changelogs
51 changes: 51 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1769,3 +1769,54 @@ def test_no_ignore_configured(self, runner):
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
)
self.assertEqual(0, result.exit_code, result.output)

@with_project(
config="""
[tool.towncrier]
title_format = "{version} - {project_date}"

[[tool.towncrier.type]]
directory = "feature"
name = "Feature"
"""
)
def test_showcontent_default_toml_array(self, runner):
"""
When configuring custom fragment types with a TOML array
`showcontent` should default to `true`.
"""
with open("foo/newsfragments/+new_feature.feature.md", "w") as f:
f.write("We added an exciting new feature!")

result = runner.invoke(
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
)
self.assertEqual(0, result.exit_code, result.output)

@with_project(
config="""
[tool.towncrier]
title_format = "{version} - {project_date}"

[[tool.towncrier.type]]
name = "Feature"

[[tool.towncrier.type]]
directory = "deps"
name = "Dependency"
"""
)
def test_directory_default_toml_array(self, runner):
"""
When configuring custom fragment types with a TOML array
the `directory` key should be optional.
"""
with open("foo/newsfragments/+new_feature.feature.md", "w") as f:
f.write("We added an exciting new feature!")
with open("foo/newsfragments/+bump_deps.deps.md", "w") as f:
f.write("We bumped our dependencies.")

result = runner.invoke(
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
)
self.assertEqual(0, result.exit_code, result.output)
Loading