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 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
10 changes: 5 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,14 @@ 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:


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

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

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

``showcontent``
A boolean value indicating whether the fragment contents should be included in the news file.
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
81 changes: 81 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import tempfile
import textwrap

from datetime import date
from pathlib import Path
Expand Down Expand Up @@ -1769,3 +1770,83 @@ 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]
package = "foo"
title_format = "{version} - {project_date}"

[[tool.towncrier.type]]
directory = "feature"
name = "Feature"
# showcontent is not defined in TOML
"""
)
def test_showcontent_default_toml_array(self, runner):
"""
When configuring custom fragment types with a TOML array
a missing `showcontent` defaults to `true`.
"""
write("foo/newsfragments/+new_feature.feature.md", "An exciting new feature!")
result = runner.invoke(_main, ["--date", "01-01-2001", "--version", "1.0.0"])
news = read("NEWS.rst")
expected = textwrap.dedent(
"""\
1.0.0 - 01-01-2001
==================

Feature
-------

- An exciting new feature!
"""
)
self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(expected, news, news)

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

[[tool.towncrier.type]]
# The `FRAGMENT.feature` files have no explicit
# `directory` configuration.
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 is optional. Its value is inferred
from the `name` configuration.
"""
write("foo/newsfragments/+new_feature.feature.md", "An exciting new feature!")
write("foo/newsfragments/+bump_deps.deps.md", "We bumped our dependencies.")
result = runner.invoke(_main, ["--date", "01-01-2001", "--version", "1.0.0"])
news = read("NEWS.rst")
expected = textwrap.dedent(
"""\
1.0.0 - 01-01-2001
==================

Feature
-------

- An exciting new feature!


Dependency
----------

- We bumped our dependencies.
"""
)
self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(expected, news, news)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave it as it is. Just a sidenote

I am not sure that it helps to repeate the actual value here.

Of we want to show full diff, we can set unittest.TestCase.maxDiff

Suggested change
self.assertEqual(expected, news, news)
self.assertEqual(expected, news, news)

Loading