Skip to content

Commit 4aa8174

Browse files
authored
handle empty issue names (#656)
2 parents 543db79 + c24e5a1 commit 4aa8174

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

src/towncrier/_builder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ def find_fragments(
177177
counter = orphan_fragment_counter[category]
178178
orphan_fragment_counter[category] += 1
179179

180-
if config.issue_pattern and not re.fullmatch(config.issue_pattern, issue):
180+
if (
181+
config.issue_pattern
182+
and issue # not orphan
183+
and not re.fullmatch(config.issue_pattern, issue)
184+
):
181185
raise ClickException(
182186
f"Issue name '{issue}' does not match the "
183187
f"configured pattern, '{config.issue_pattern}'"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
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.

src/towncrier/test/test_check.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,32 @@ def test_issue_pattern(self, runner):
529529
"pyproject.toml",
530530
extra_config='issue_pattern = "\\\\d+"',
531531
)
532-
write(
533-
"foo/newsfragments/AAA.BBB.feature.md",
534-
"This fragment has an invalid name (should be digits only)",
535-
)
536532
write(
537533
"foo/newsfragments/123.feature",
538534
"This fragment has a valid name",
539535
)
536+
write(
537+
"foo/newsfragments/+abcdefg.feature",
538+
"This fragment has a valid name (orphan fragment)",
539+
)
540+
commit("add stuff")
541+
542+
result = runner.invoke(towncrier_check, ["--compare-with", "main"])
543+
self.assertEqual(0, result.exit_code, result.output)
544+
545+
@with_isolated_runner
546+
def test_issue_pattern_invalid_with_suffix(self, runner):
547+
"""
548+
Fails if an issue name goes against the configured pattern.
549+
"""
550+
create_project(
551+
"pyproject.toml",
552+
extra_config='issue_pattern = "\\\\d+"',
553+
)
554+
write(
555+
"foo/newsfragments/AAA.BBB.feature.md",
556+
"This fragment has an invalid name (should be digits only)",
557+
)
540558
commit("add stuff")
541559

542560
result = runner.invoke(towncrier_check, ["--compare-with", "main"])
@@ -545,11 +563,25 @@ def test_issue_pattern(self, runner):
545563
"Error: Issue name 'AAA.BBB' does not match the configured pattern, '\\d+'",
546564
result.output,
547565
)
548-
self.assertNotIn(
549-
"Error: Issue '123' does not match the configured pattern, '\\d+'",
550-
result.output,
566+
567+
@with_isolated_runner
568+
def test_issue_pattern_invalid(self, runner):
569+
"""
570+
Fails if an issue name goes against the configured pattern.
571+
"""
572+
create_project(
573+
"pyproject.toml",
574+
extra_config='issue_pattern = "\\\\d+"',
551575
)
552-
self.assertNotIn(
553-
"Error: Issue '123.feature' does not match the configured pattern, '\\d+'",
576+
write(
577+
"foo/newsfragments/AAA.BBB.feature",
578+
"This fragment has an invalid name (should be digits only)",
579+
)
580+
commit("add stuff")
581+
582+
result = runner.invoke(towncrier_check, ["--compare-with", "main"])
583+
self.assertEqual(1, result.exit_code, result.output)
584+
self.assertIn(
585+
"Error: Issue name 'AAA.BBB' does not match the configured pattern, '\\d+'",
554586
result.output,
555587
)

0 commit comments

Comments
 (0)