From b795310961e8510b5d42987b7dde808be5abb7d5 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Tue, 6 Aug 2024 11:40:34 +0300 Subject: [PATCH] Improve suffix parsing in `issue_pattern` --- src/towncrier/_builder.py | 9 +++------ src/towncrier/newsfragments/654.bugfix.rst | 1 + src/towncrier/test/test_check.py | 10 +++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 src/towncrier/newsfragments/654.bugfix.rst diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index a06f6cd2..8a2c38d3 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -176,13 +176,10 @@ def find_fragments( # Use and increment the orphan news fragment counter. counter = orphan_fragment_counter[category] orphan_fragment_counter[category] += 1 - if config.issue_pattern and ( - not re.fullmatch( - config.issue_pattern, issue_name := Path(basename).stem - ) - ): + + if config.issue_pattern and not re.fullmatch(config.issue_pattern, issue): raise ClickException( - f"File name '{issue_name}' does not match the " + f"Issue name '{issue}' does not match the " f"given issue pattern, '{config.issue_pattern}'" ) full_filename = os.path.join(section_dir, basename) diff --git a/src/towncrier/newsfragments/654.bugfix.rst b/src/towncrier/newsfragments/654.bugfix.rst new file mode 100644 index 00000000..0a827f70 --- /dev/null +++ b/src/towncrier/newsfragments/654.bugfix.rst @@ -0,0 +1 @@ +Fixed an issue where `issue_template` failed recognizing the issue name of files with a non-category suffix (`.md`) diff --git a/src/towncrier/test/test_check.py b/src/towncrier/test/test_check.py index c4f53c4b..c0476ac2 100644 --- a/src/towncrier/test/test_check.py +++ b/src/towncrier/test/test_check.py @@ -530,7 +530,7 @@ def test_issue_pattern(self, runner): extra_config='issue_pattern = "\\\\d+"', ) write( - "foo/newsfragments/AAA.BBB.feature", + "foo/newsfragments/AAA.BBB.feature.md", "This fragment has an invalid name (should be digits only)", ) write( @@ -542,10 +542,14 @@ def test_issue_pattern(self, runner): result = runner.invoke(towncrier_check, ["--compare-with", "main"]) self.assertEqual(1, result.exit_code, result.output) self.assertIn( - "Error: File name 'AAA.BBB' does not match the given issue pattern, '\\d+'", + "Error: Issue name 'AAA.BBB' does not match the given issue pattern, '\\d+'", result.output, ) self.assertNotIn( - "Error: File name '123' does not match the given issue pattern, '\\d+'", + "Error: Issue '123' does not match the given issue pattern, '\\d+'", + result.output, + ) + self.assertNotIn( + "Error: Issue '123.feature' does not match the given issue pattern, '\\d+'", result.output, )