Skip to content

Commit 2b9fd49

Browse files
committed
Make directory default to name.lower() for custom newfragment types
1 parent 8d92711 commit 2b9fd49

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

docs/configuration.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,16 @@ If you use this way to configure custom fragment types, ensure there is no ``too
288288
Each table within this array has the following mandatory keys:
289289

290290

291-
``directory``
292-
The type / category of the fragment.
293-
294-
``name``
291+
``name`` (required)
295292
The description of the fragment type, as it must be included
296293
in the news file.
297294

298-
``showcontent``
295+
``directory`` (optional)
296+
The type / category of the fragment.
297+
298+
Defaults to ``name.lower()``.
299+
300+
``showcontent`` (optional)
299301
A boolean value indicating whether the fragment contents should be included in the news file.
300302

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

308-
``check``
310+
``check`` (optional)
309311
A boolean value indicating whether the fragment should be considered by the ``towncrier check`` command.
310312

311313
``true`` by default.
@@ -316,9 +318,7 @@ For example:
316318
317319
[tool.towncrier]
318320
[[tool.towncrier.type]]
319-
directory = "deprecation"
320321
name = "Deprecations"
321-
showcontent = true
322322
323323
[[tool.towncrier.type]]
324324
directory = "chore"

docs/markdown.rst

-6
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,21 @@ Put the following into your ``pyproject.toml`` or ``towncrier.toml``:
2525
issue_format = "[#{issue}](https://github.com/twisted/my-project/issues/{issue})"
2626
2727
[[tool.towncrier.type]]
28-
directory = "security"
2928
name = "Security"
3029
3130
[[tool.towncrier.type]]
32-
directory = "removed"
3331
name = "Removed"
3432
3533
[[tool.towncrier.type]]
36-
directory = "deprecated"
3734
name = "Deprecated"
3835
3936
[[tool.towncrier.type]]
40-
directory = "added"
4137
name = "Added"
4238
4339
[[tool.towncrier.type]]
44-
directory = "changed"
4540
name = "Changed"
4641
4742
[[tool.towncrier.type]]
48-
directory = "fixed"
4943
name = "Fixed"
5044
5145

src/towncrier/_settings/fragment_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def load(self) -> Mapping[str, Mapping[str, Any]]:
7676
types = {}
7777
types_config = self.config["type"]
7878
for type_config in types_config:
79-
directory = type_config["directory"]
8079
fragment_type_name = type_config["name"]
80+
directory = type_config.get("directory", fragment_type_name.lower())
8181
is_content_required = type_config.get("showcontent", True)
8282
check = type_config.get("check", True)
8383
types[directory] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
More simple configuration for Keep a Changelog style changelogs

src/towncrier/test/test_build.py

+28
Original file line numberDiff line numberDiff line change
@@ -1792,3 +1792,31 @@ def test_showcontent_default_toml_array(self, runner):
17921792
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
17931793
)
17941794
self.assertEqual(0, result.exit_code, result.output)
1795+
1796+
@with_project(
1797+
config="""
1798+
[tool.towncrier]
1799+
title_format = "{version} - {project_date}"
1800+
1801+
[[tool.towncrier.type]]
1802+
name = "Feature"
1803+
1804+
[[tool.towncrier.type]]
1805+
directory = "deps"
1806+
name = "Dependency"
1807+
"""
1808+
)
1809+
def test_directory_default_toml_array(self, runner):
1810+
"""
1811+
When configuring custom fragment types with a TOML array
1812+
the `directory` key should be optional.
1813+
"""
1814+
with open("foo/newsfragments/+new_feature.feature.md", "w") as f:
1815+
f.write("We added an exciting new feature!")
1816+
with open("foo/newsfragments/+bump_deps.deps.md", "w") as f:
1817+
f.write("We bumped our dependencies.")
1818+
1819+
result = runner.invoke(
1820+
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
1821+
)
1822+
self.assertEqual(0, result.exit_code, result.output)

0 commit comments

Comments
 (0)