Skip to content

Commit

Permalink
fix: Also render title in markdown template without name
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Apr 18, 2024
1 parent 212a938 commit be83bf2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/587.bugfix
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/towncrier/templates/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() %}
Expand Down
47 changes: 47 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- towncrier release notes start -->
""",
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
<!-- towncrier release notes start -->
# 1.2.3 (01-01-2001)
### Features
- Adds levitation (#123)
"""
)

self.assertEqual(expected_output, output)

@with_project(
config="""
[tool.towncrier]
Expand Down

0 comments on commit be83bf2

Please sign in to comment.