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

Orphans in non showcontent categories #612

Merged
merged 10 commits into from
Jun 14, 2024
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ These may include the following optional keys:

``true`` by default.

.. note::

Orphan fragments (those without an issue number) always have their content included.
If a fragment was created, it means that information is important for end users.

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:

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

``true`` by default.

.. note::

Orphan fragments (those without an issue number) always have their content included.
If a fragment was created, it means that information is important for end users.

For example:

.. code-block:: toml
Expand Down
6 changes: 5 additions & 1 deletion src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ def split_fragments(
# Assume the text is formatted correctly
content = content.rstrip()

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

texts = section.setdefault(category, {})
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/612.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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.
13 changes: 3 additions & 10 deletions src/towncrier/templates/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{% for category, val in definitions.items() if category in sections[section] %}
### {{ definitions[category]['name'] }}

{% if definitions[category]['showcontent'] %}
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should add an 612.removal fragment, informat that when showcontent = False the template will no longer receive the fragment content.

This is a note, just in case someone was missusing this feature with a custom template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's some confusion here. The existing behaviour is already that fragment content is not sent to the template (https://github.com/twisted/towncrier/pull/612/files#diff-36db088409efe07783d49792a18cec6ae3778ace338bf1cd08daa8a3fce29e93L166). This change just means that orphan fragment contents are sent.

Copy link
Member

Choose a reason for hiding this comment

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

True. My bad. I misinterpreted the changes in the code.

{% for text, values in sections[section][category].items() %}
- {{ text }}
{%- if values %}
Expand All @@ -24,24 +23,18 @@

(
{%- else %}
(
{% if text %} ({% endif %}
{%- endif -%}
{%- for issue in values %}
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
{%- endfor %}
)
{% if text %}){% endif %}

{% else %}

{% endif %}
{% endfor %}

{% else %}
- {% for issue in sections[section][category][''] %}
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
{% endfor %}


{% endif %}
{% if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %}
{% for issue in issues_by_category[section][category] %}
{{ issue }}
Expand Down
7 changes: 1 addition & 6 deletions src/towncrier/templates/default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
{{ definitions[category]['name'] }}
{{ underline * definitions[category]['name']|length }}

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

{% endfor %}

{% else %}
- {{ sections[section][category]['']|join(', ') }}

{% endif %}
{% if sections[section][category]|length == 0 %}
No significant changes.

Expand Down
109 changes: 109 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,115 @@ def test_with_topline_and_template_and_draft(self, runner):
- Adds levitation


"""
)

self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(expected_output, result.output)

@with_project(
config="""
[tool.towncrier]
"""
)
def test_orphans_in_non_showcontent(self, runner):
"""
When ``showcontent`` is false (like in the ``misc`` category by default),
orphans are still rendered because they don't have an issue number to display.
"""
os.mkdir("newsfragments")
with open("newsfragments/123.misc", "w") as f:
f.write("Misc")
with open("newsfragments/345.misc", "w") as f:
f.write("Another misc")
with open("newsfragments/+.misc", "w") as f:
f.write("Orphan misc still displayed!")
with open("newsfragments/+2.misc", "w") as f:
f.write("Another orphan misc still displayed!")

result = runner.invoke(
_main,
[
"--version=7.8.9",
"--date=20-01-2001",
"--draft",
],
)

expected_output = dedent(
"""\
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

7.8.9 (20-01-2001)
==================

Misc
----

- #123, #345
- Another orphan misc still displayed!
- Orphan misc still displayed!



"""
)

self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(expected_output, result.output)

@with_project(
config="""
[tool.towncrier]
filename = "CHANGES.md"
"""
)
def test_orphans_in_non_showcontent_markdown(self, runner):
"""
When ``showcontent`` is false (like in the ``misc`` category by default),
orphans are still rendered because they don't have an issue number to display.
"""
os.mkdir("newsfragments")
with open("newsfragments/123.misc", "w") as f:
f.write("Misc")
with open("newsfragments/345.misc", "w") as f:
f.write("Another misc")
with open("newsfragments/+.misc", "w") as f:
f.write("Orphan misc still displayed!")
with open("newsfragments/+2.misc", "w") as f:
f.write("Another orphan misc still displayed!")

result = runner.invoke(
_main,
[
"--version=7.8.9",
"--date=20-01-2001",
"--draft",
],
)

expected_output = dedent(
"""\
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

# 7.8.9 (20-01-2001)

### Misc

- #123, #345
- Another orphan misc still displayed!
- Orphan misc still displayed!



"""
)

Expand Down
Loading