Skip to content

Commit 3af0c53

Browse files
authored
Simple configuration for Keep a Changelog style changelogs (#693)
2 parents 26b8d30 + c829f72 commit 3af0c53

File tree

5 files changed

+89
-19
lines changed

5 files changed

+89
-19
lines changed

docs/configuration.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ 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+
``name`` (required)
292+
The description of the fragment type, as it must be included
293+
in the news file.
294+
291295
``directory``
292296
The type / category of the fragment.
293297

294-
``name``
295-
The description of the fragment type, as it must be included
296-
in the news file.
298+
Defaults to ``name.lower()``.
297299

298300
``showcontent``
299301
A boolean value indicating whether the fragment contents should be included in the news file.
@@ -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

-12
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,22 @@ 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"
30-
showcontent = true
3129
3230
[[tool.towncrier.type]]
33-
directory = "removed"
3431
name = "Removed"
35-
showcontent = true
3632
3733
[[tool.towncrier.type]]
38-
directory = "deprecated"
3934
name = "Deprecated"
40-
showcontent = true
4135
4236
[[tool.towncrier.type]]
43-
directory = "added"
4437
name = "Added"
45-
showcontent = true
4638
4739
[[tool.towncrier.type]]
48-
directory = "changed"
4940
name = "Changed"
50-
showcontent = true
5141
5242
[[tool.towncrier.type]]
53-
directory = "fixed"
5443
name = "Fixed"
55-
showcontent = true
5644
5745
5846

src/towncrier/_settings/fragment_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ 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"]
81-
is_content_required = type_config["showcontent"]
80+
directory = type_config.get("directory", fragment_type_name.lower())
81+
is_content_required = type_config.get("showcontent", True)
8282
check = type_config.get("check", True)
8383
types[directory] = {
8484
"name": fragment_type_name,
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

+81
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import tempfile
6+
import textwrap
67

78
from datetime import date
89
from pathlib import Path
@@ -1769,3 +1770,83 @@ def test_no_ignore_configured(self, runner):
17691770
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
17701771
)
17711772
self.assertEqual(0, result.exit_code, result.output)
1773+
1774+
@with_project(
1775+
config="""
1776+
[tool.towncrier]
1777+
package = "foo"
1778+
title_format = "{version} - {project_date}"
1779+
1780+
[[tool.towncrier.type]]
1781+
directory = "feature"
1782+
name = "Feature"
1783+
# showcontent is not defined in TOML
1784+
"""
1785+
)
1786+
def test_showcontent_default_toml_array(self, runner):
1787+
"""
1788+
When configuring custom fragment types with a TOML array
1789+
a missing `showcontent` defaults to `true`.
1790+
"""
1791+
write("foo/newsfragments/+new_feature.feature.md", "An exciting new feature!")
1792+
result = runner.invoke(_main, ["--date", "01-01-2001", "--version", "1.0.0"])
1793+
news = read("NEWS.rst")
1794+
expected = textwrap.dedent(
1795+
"""\
1796+
1.0.0 - 01-01-2001
1797+
==================
1798+
1799+
Feature
1800+
-------
1801+
1802+
- An exciting new feature!
1803+
"""
1804+
)
1805+
self.assertEqual(0, result.exit_code, result.output)
1806+
self.assertEqual(expected, news, news)
1807+
1808+
@with_project(
1809+
config="""
1810+
[tool.towncrier]
1811+
package = "foo"
1812+
title_format = "{version} - {project_date}"
1813+
1814+
[[tool.towncrier.type]]
1815+
# The `FRAGMENT.feature` files have no explicit
1816+
# `directory` configuration.
1817+
name = "Feature"
1818+
1819+
[[tool.towncrier.type]]
1820+
directory = "deps"
1821+
name = "Dependency"
1822+
"""
1823+
)
1824+
def test_directory_default_toml_array(self, runner):
1825+
"""
1826+
When configuring custom fragment types with a TOML array
1827+
the `directory` key is optional. Its value is inferred
1828+
from the `name` configuration.
1829+
"""
1830+
write("foo/newsfragments/+new_feature.feature.md", "An exciting new feature!")
1831+
write("foo/newsfragments/+bump_deps.deps.md", "We bumped our dependencies.")
1832+
result = runner.invoke(_main, ["--date", "01-01-2001", "--version", "1.0.0"])
1833+
news = read("NEWS.rst")
1834+
expected = textwrap.dedent(
1835+
"""\
1836+
1.0.0 - 01-01-2001
1837+
==================
1838+
1839+
Feature
1840+
-------
1841+
1842+
- An exciting new feature!
1843+
1844+
1845+
Dependency
1846+
----------
1847+
1848+
- We bumped our dependencies.
1849+
"""
1850+
)
1851+
self.assertEqual(0, result.exit_code, result.output)
1852+
self.assertEqual(expected, news, news)

0 commit comments

Comments
 (0)