From d87b84b517fada2b6abf0c87e4f544ce7741e697 Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:37:34 +0300 Subject: [PATCH 1/4] handle empty issue names --- src/towncrier/_builder.py | 6 ++- src/towncrier/newsfragments/655.bugfix.rst | 1 + src/towncrier/test/test_check.py | 50 ++++++++++++++++++---- 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/towncrier/newsfragments/655.bugfix.rst diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index 878d3b17..fa3ed0bf 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -177,7 +177,11 @@ def find_fragments( counter = orphan_fragment_counter[category] orphan_fragment_counter[category] += 1 - if config.issue_pattern and not re.fullmatch(config.issue_pattern, issue): + if ( + config.issue_pattern + and issue # doesn't start with + + and not re.fullmatch(config.issue_pattern, issue) + ): raise ClickException( f"Issue name '{issue}' does not match the " f"configured pattern, '{config.issue_pattern}'" diff --git a/src/towncrier/newsfragments/655.bugfix.rst b/src/towncrier/newsfragments/655.bugfix.rst new file mode 100644 index 00000000..e43935c7 --- /dev/null +++ b/src/towncrier/newsfragments/655.bugfix.rst @@ -0,0 +1 @@ +Fixed an issue where non-issue fragments (e.g. +abc1234.feature) would fail when an `issue_pattern` is configured. Non-issue fragments are now excempt from `issue_pattern` checks. diff --git a/src/towncrier/test/test_check.py b/src/towncrier/test/test_check.py index ddf8afcc..70900410 100644 --- a/src/towncrier/test/test_check.py +++ b/src/towncrier/test/test_check.py @@ -529,14 +529,32 @@ def test_issue_pattern(self, runner): "pyproject.toml", extra_config='issue_pattern = "\\\\d+"', ) - write( - "foo/newsfragments/AAA.BBB.feature.md", - "This fragment has an invalid name (should be digits only)", - ) write( "foo/newsfragments/123.feature", "This fragment has a valid name", ) + write( + "foo/newsfragments/+abcdefg.feature", + "This fragment has a valid name (no issue name)", + ) + commit("add stuff") + + result = runner.invoke(towncrier_check, ["--compare-with", "main"]) + self.assertEqual(0, result.exit_code, result.output) + + @with_isolated_runner + def test_issue_pattern_invalid_with_suffix(self, runner): + """ + Fails if an issue name goes against the configured pattern. + """ + create_project( + "pyproject.toml", + extra_config='issue_pattern = "\\\\d+"', + ) + write( + "foo/newsfragments/AAA.BBB.feature.md", + "This fragment has an invalid name (should be digits only)", + ) commit("add stuff") result = runner.invoke(towncrier_check, ["--compare-with", "main"]) @@ -545,11 +563,25 @@ def test_issue_pattern(self, runner): "Error: Issue name 'AAA.BBB' does not match the configured pattern, '\\d+'", result.output, ) - self.assertNotIn( - "Error: Issue '123' does not match the configured pattern, '\\d+'", - result.output, + + @with_isolated_runner + def test_issue_pattern_invalid(self, runner): + """ + Fails if an issue name goes against the configured pattern. + """ + create_project( + "pyproject.toml", + extra_config='issue_pattern = "\\\\d+"', ) - self.assertNotIn( - "Error: Issue '123.feature' does not match the configured pattern, '\\d+'", + write( + "foo/newsfragments/AAA.BBB.feature", + "This fragment has an invalid name (should be digits only)", + ) + commit("add stuff") + + result = runner.invoke(towncrier_check, ["--compare-with", "main"]) + self.assertEqual(1, result.exit_code, result.output) + self.assertIn( + "Error: Issue name 'AAA.BBB' does not match the configured pattern, '\\d+'", result.output, ) From 4a94d4a99f9560ee02f027f33ec41325b5bd51ab Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Tue, 6 Aug 2024 15:46:15 +0100 Subject: [PATCH 2/4] Use terminology from tutorial --- src/towncrier/newsfragments/655.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/towncrier/newsfragments/655.bugfix.rst b/src/towncrier/newsfragments/655.bugfix.rst index e43935c7..ef5fde60 100644 --- a/src/towncrier/newsfragments/655.bugfix.rst +++ b/src/towncrier/newsfragments/655.bugfix.rst @@ -1 +1 @@ -Fixed an issue where non-issue fragments (e.g. +abc1234.feature) would fail when an `issue_pattern` is configured. Non-issue fragments are now excempt from `issue_pattern` checks. +Fixed a bug where orphan news fragments (e.g. +abc1234.feature) would fail when an `issue_pattern` is configured. Orphan news fragments are now excempt from `issue_pattern` checks. From 51129c7042f0a7783cf3a6d9630bbde2fd50216c Mon Sep 17 00:00:00 2001 From: dorschw <81086590+dorschw@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:47:55 +0300 Subject: [PATCH 3/4] fix comment --- src/towncrier/_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index fa3ed0bf..dca09da6 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -179,7 +179,7 @@ def find_fragments( if ( config.issue_pattern - and issue # doesn't start with + + and issue # not orphan and not re.fullmatch(config.issue_pattern, issue) ): raise ClickException( From c24e5a1bdcb7b524181d4a84cfa991b8e498e8e4 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Tue, 6 Aug 2024 15:55:15 +0100 Subject: [PATCH 4/4] Update src/towncrier/test/test_check.py --- src/towncrier/test/test_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/towncrier/test/test_check.py b/src/towncrier/test/test_check.py index 70900410..9d8c05aa 100644 --- a/src/towncrier/test/test_check.py +++ b/src/towncrier/test/test_check.py @@ -535,7 +535,7 @@ def test_issue_pattern(self, runner): ) write( "foo/newsfragments/+abcdefg.feature", - "This fragment has a valid name (no issue name)", + "This fragment has a valid name (orphan fragment)", ) commit("add stuff")