Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle empty issue names #656

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/655.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
adiroiban marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 41 additions & 9 deletions src/towncrier/test/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
adiroiban marked this conversation as resolved.
Show resolved Hide resolved
)
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"])
Expand All @@ -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,
)
Loading