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

Improve suffix parsing in issue_pattern #654

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,11 @@ 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"given issue pattern, '{config.issue_pattern}'"
f"Issue name '{issue}' does not match the "
f"configured pattern, '{config.issue_pattern}'"
)
full_filename = os.path.join(section_dir, basename)
fragment_files.append((full_filename, category))
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/654.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where `issue_template` failed recognizing the issue name of files with a non-category suffix (`.md`)
10 changes: 7 additions & 3 deletions src/towncrier/test/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 configured 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 configured pattern, '\\d+'",
result.output,
)
self.assertNotIn(
"Error: Issue '123.feature' does not match the configured pattern, '\\d+'",
result.output,
)
Loading