Skip to content

Commit 9ef9fcd

Browse files
committed
Make directory default to name.lower() for custom newfragment types
1 parent e820cd0 commit 9ef9fcd

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-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] = {

src/towncrier/test/test_build.py

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

0 commit comments

Comments
 (0)