From be83bf2bc25016a37cba81f5f98ae8150a8ed1ed Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 15 Apr 2024 18:37:25 +0200 Subject: [PATCH] fix: Also render title in markdown template without name --- src/towncrier/newsfragments/587.bugfix | 1 + src/towncrier/templates/default.md | 2 +- src/towncrier/test/test_build.py | 47 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/towncrier/newsfragments/587.bugfix diff --git a/src/towncrier/newsfragments/587.bugfix b/src/towncrier/newsfragments/587.bugfix new file mode 100644 index 00000000..1ab7ba62 --- /dev/null +++ b/src/towncrier/newsfragments/587.bugfix @@ -0,0 +1 @@ +The default Markdown template now renders a title containing the release version and date, even when the `name` configuration is left empty. diff --git a/src/towncrier/templates/default.md b/src/towncrier/templates/default.md index 9afb5c49..cc894f60 100644 --- a/src/towncrier/templates/default.md +++ b/src/towncrier/templates/default.md @@ -2,7 +2,7 @@ {% if versiondata.name %} # {{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }}) {% else %} -{{ versiondata.version }} ({{ versiondata.date }}) +# {{ versiondata.version }} ({{ versiondata.date }}) {% endif %} {% endif %} {% for section, _ in sections.items() %} diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index 76f6e8aa..241425e9 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -1248,6 +1248,53 @@ def test_default_start_string_markdown(self, runner): self.assertEqual(expected_output, output) + @with_project( + config=""" + [tool.towncrier] + name = "" + directory = "changes" + filename = "NEWS.md" + version = "1.2.3" + """ + ) + def test_markdown_no_name_title(self, runner): + """ + When configured with an empty `name` option, + the default template used for Markdown + renders the title of the release note with just + the version number and release date. + """ + write("changes/123.feature", "Adds levitation") + write( + "NEWS.md", + contents=""" + A line + + + """, + dedent=True, + ) + + result = runner.invoke(_main, ["--date", "01-01-2001"], catch_exceptions=False) + self.assertEqual(0, result.exit_code, result.output) + output = read("NEWS.md") + + expected_output = dedent( + """ + A line + + + + # 1.2.3 (01-01-2001) + + ### Features + + - Adds levitation (#123) + """ + ) + + self.assertEqual(expected_output, output) + @with_project( config=""" [tool.towncrier]