Skip to content

Commit

Permalink
automatically ignore template files
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha committed Jul 31, 2024
1 parent 68a7a3b commit 36cb968
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def find_fragments(
If strict, raise ClickException if any fragments have an invalid name.
"""
ignored_files = {".gitignore", ".keep", "readme", "readme.md", "readme.rst"}
if isinstance(config.template, str):
ignored_files.add(config.template)
if config.ignore:
ignored_files.update(filename.lower() for filename in config.ignore)

Expand Down
24 changes: 24 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,30 @@ def test_invalid_fragment_name(self, runner):
self.assertEqual(1, result.exit_code, result.output)
self.assertIn("Invalid news fragment name: feature.124", result.output)

@with_project(
config="""
[tool.towncrier]
package = "foo"
template = ["template.jinja"]
"""
)
def test_ignored_template_string(self, runner):
"""
Files used in `template` are automatically ignored.
"""
with open("foo/newsfragments/123.feature", "w") as f:
f.write("This has valid filename (control case)")
with open("foo/newsfragments/template.jinja", "w") as f:
f.write("This template has been automatically ignored")
with open("foo/newsfragments/.gitignore", "w") as f:
f.write("gitignore is automatically ignored")

result = runner.invoke(
_main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
)
self.assertEqual(0, result.exit_code, result.output)


@with_project()
def test_no_ignore_configured(self, runner):
"""
Expand Down

0 comments on commit 36cb968

Please sign in to comment.