Skip to content

Commit 09819ac

Browse files
SmileyChrispre-commit-ci[bot]adiroiban
authored
Orphans in non showcontent categories (#612)
* Always content for orphans, since they don't have a concept of tickets * Add tests for orphans in non showcontent categories * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add newsfragment * Add a note in the configuration docs about the change to orphan fragments in non-showcontent categories * Use rst admonitions for the showcontent notes * Refactor rendering of title via `config.title_format` (#610) * Refactor rendering of title via config.title_format * Add newsfragment * Config docs * Fix restructuredtext formatting error * Refactor issue_key function to sort issues in a human-friendly way (#608) * Refactor issue_key function to sort issues in a human-friendly way * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename newsfragment * Small improvement to test to show how text with numeric issues are sorted * Update src/towncrier/_builder.py docstring grammar Co-authored-by: Adi Roiban <[email protected]> * clarify new behaviour in newsfragment * Add some docstrings/comments to tests * linelength fix * Clarify news fragments vs tickets Co-authored-by: Adi Roiban <[email protected]> * Consistent use of "issue" rather than "ticket" * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * typo --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adi Roiban <[email protected]> * variable now called issue instead of ticket --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adi Roiban <[email protected]>
1 parent 52412ac commit 09819ac

File tree

6 files changed

+129
-17
lines changed

6 files changed

+129
-17
lines changed

docs/configuration.rst

+10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ These may include the following optional keys:
216216

217217
``true`` by default.
218218

219+
.. note::
220+
221+
Orphan fragments (those without an issue number) always have their content included.
222+
If a fragment was created, it means that information is important for end users.
223+
219224
For example, if you want your custom fragment types to be ``["feat", "fix", "chore",]`` and you want all of them to use the default configuration except ``"chore"`` you can do it as follows:
220225

221226
.. code-block:: toml
@@ -257,6 +262,11 @@ Each table within this array has the following mandatory keys:
257262

258263
``true`` by default.
259264

265+
.. note::
266+
267+
Orphan fragments (those without an issue number) always have their content included.
268+
If a fragment was created, it means that information is important for end users.
269+
260270
For example:
261271

262272
.. code-block:: toml

src/towncrier/_builder.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ def split_fragments(
191191
# Assume the text is formatted correctly
192192
content = content.rstrip()
193193

194-
if definitions[category]["showcontent"] is False:
194+
if definitions[category]["showcontent"] is False and issue:
195+
# If this category is not supposed to show content (and we have an
196+
# issue) then we should just add the issue to the section rather than
197+
# the content. If there isn't an issue, still add the content so that
198+
# it's recorded.
195199
content = ""
196200

197201
texts = section.setdefault(category, {})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Orphan news fragments, fragments not associated with an issue, will now still show in categories that are marked to not show content, since they do not have an issue number to show.

src/towncrier/templates/default.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
{% for category, val in definitions.items() if category in sections[section] %}
1616
### {{ definitions[category]['name'] }}
1717

18-
{% if definitions[category]['showcontent'] %}
1918
{% for text, values in sections[section][category].items() %}
2019
- {{ text }}
2120
{%- if values %}
@@ -24,24 +23,18 @@
2423

2524
(
2625
{%- else %}
27-
(
26+
{% if text %} ({% endif %}
2827
{%- endif -%}
2928
{%- for issue in values %}
3029
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
3130
{%- endfor %}
32-
)
31+
{% if text %}){% endif %}
32+
3333
{% else %}
3434

3535
{% endif %}
3636
{% endfor %}
3737

38-
{% else %}
39-
- {% for issue in sections[section][category][''] %}
40-
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
41-
{% endfor %}
42-
43-
44-
{% endif %}
4538
{% if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %}
4639
{% for issue in issues_by_category[section][category] %}
4740
{{ issue }}

src/towncrier/templates/default.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@
1818
{{ definitions[category]['name'] }}
1919
{{ underline * definitions[category]['name']|length }}
2020

21-
{% if definitions[category]['showcontent'] %}
2221
{% for text, values in sections[section][category].items() %}
23-
- {{ text }}{% if values %} ({{ values|join(', ') }}){% endif %}
22+
- {% if text %}{{ text }}{% if values %} ({{ values|join(', ') }}){% endif %}{% else %}{{ values|join(', ') }}{% endif %}
2423

2524
{% endfor %}
2625

27-
{% else %}
28-
- {{ sections[section][category]['']|join(', ') }}
29-
30-
{% endif %}
3126
{% if sections[section][category]|length == 0 %}
3227
No significant changes.
3328

src/towncrier/test/test_build.py

+109
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,115 @@ def test_with_topline_and_template_and_draft(self, runner):
14161416
- Adds levitation
14171417
14181418
1419+
"""
1420+
)
1421+
1422+
self.assertEqual(0, result.exit_code, result.output)
1423+
self.assertEqual(expected_output, result.output)
1424+
1425+
@with_project(
1426+
config="""
1427+
[tool.towncrier]
1428+
"""
1429+
)
1430+
def test_orphans_in_non_showcontent(self, runner):
1431+
"""
1432+
When ``showcontent`` is false (like in the ``misc`` category by default),
1433+
orphans are still rendered because they don't have an issue number to display.
1434+
"""
1435+
os.mkdir("newsfragments")
1436+
with open("newsfragments/123.misc", "w") as f:
1437+
f.write("Misc")
1438+
with open("newsfragments/345.misc", "w") as f:
1439+
f.write("Another misc")
1440+
with open("newsfragments/+.misc", "w") as f:
1441+
f.write("Orphan misc still displayed!")
1442+
with open("newsfragments/+2.misc", "w") as f:
1443+
f.write("Another orphan misc still displayed!")
1444+
1445+
result = runner.invoke(
1446+
_main,
1447+
[
1448+
"--version=7.8.9",
1449+
"--date=20-01-2001",
1450+
"--draft",
1451+
],
1452+
)
1453+
1454+
expected_output = dedent(
1455+
"""\
1456+
Loading template...
1457+
Finding news fragments...
1458+
Rendering news fragments...
1459+
Draft only -- nothing has been written.
1460+
What is seen below is what would be written.
1461+
1462+
7.8.9 (20-01-2001)
1463+
==================
1464+
1465+
Misc
1466+
----
1467+
1468+
- #123, #345
1469+
- Another orphan misc still displayed!
1470+
- Orphan misc still displayed!
1471+
1472+
1473+
1474+
"""
1475+
)
1476+
1477+
self.assertEqual(0, result.exit_code, result.output)
1478+
self.assertEqual(expected_output, result.output)
1479+
1480+
@with_project(
1481+
config="""
1482+
[tool.towncrier]
1483+
filename = "CHANGES.md"
1484+
"""
1485+
)
1486+
def test_orphans_in_non_showcontent_markdown(self, runner):
1487+
"""
1488+
When ``showcontent`` is false (like in the ``misc`` category by default),
1489+
orphans are still rendered because they don't have an issue number to display.
1490+
"""
1491+
os.mkdir("newsfragments")
1492+
with open("newsfragments/123.misc", "w") as f:
1493+
f.write("Misc")
1494+
with open("newsfragments/345.misc", "w") as f:
1495+
f.write("Another misc")
1496+
with open("newsfragments/+.misc", "w") as f:
1497+
f.write("Orphan misc still displayed!")
1498+
with open("newsfragments/+2.misc", "w") as f:
1499+
f.write("Another orphan misc still displayed!")
1500+
1501+
result = runner.invoke(
1502+
_main,
1503+
[
1504+
"--version=7.8.9",
1505+
"--date=20-01-2001",
1506+
"--draft",
1507+
],
1508+
)
1509+
1510+
expected_output = dedent(
1511+
"""\
1512+
Loading template...
1513+
Finding news fragments...
1514+
Rendering news fragments...
1515+
Draft only -- nothing has been written.
1516+
What is seen below is what would be written.
1517+
1518+
# 7.8.9 (20-01-2001)
1519+
1520+
### Misc
1521+
1522+
- #123, #345
1523+
- Another orphan misc still displayed!
1524+
- Orphan misc still displayed!
1525+
1526+
1527+
14191528
"""
14201529
)
14211530

0 commit comments

Comments
 (0)