Skip to content

Commit 50fc1e6

Browse files
Fix incorrect handling of orphan fragment names consists of only digits (#588)
* Don't lose the flag at the start of decimal only orphans Fixes #584 * Add news fragment * Reword news fragment to be less git-commenty * mention why we're removing leading zeros --------- Co-authored-by: Adi Roiban <[email protected]>
1 parent 2908a62 commit 50fc1e6

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/towncrier/_builder.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
from jinja2 import Template
1414

1515

16-
def strip_if_integer_string(s: str) -> str:
17-
try:
18-
i = int(s)
19-
except ValueError:
20-
return s
21-
22-
return str(i)
23-
24-
2516
# Returns ticket, category and counter or (None, None, None) if the basename
2617
# could not be parsed or doesn't contain a valid category.
2718
def parse_newfragment_basename(
@@ -45,7 +36,11 @@ def parse_newfragment_basename(
4536
# NOTE: This allows news fragment names like fix-1.2.3.feature or
4637
# something-cool.feature.ext for projects that don't use ticket
4738
# numbers in news fragment names.
48-
ticket = strip_if_integer_string(".".join(parts[0:i]))
39+
ticket = ".".join(parts[0:i]).strip()
40+
# If the ticket is an integer, remove any leading zeros (to resolve
41+
# issue #126).
42+
if ticket.isdigit():
43+
ticket = str(int(ticket))
4944
counter = 0
5045
# Use the following part as the counter if it exists and is a valid
5146
# digit.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Orphan news fragments, fragments not associated with an issue, consisting of only digits (e.g. '+12345678.feature') now retain their leading marker character.

src/towncrier/test/test_builder.py

+7
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,10 @@ def test_orphan_with_dotted_number(self):
125125
parse_newfragment_basename("+orphan_12.3.feature", ["feature"]),
126126
("+orphan_12.3", "feature", 0),
127127
)
128+
129+
def test_orphan_all_digits(self):
130+
"""Orphaned snippets can consist of only digits."""
131+
self.assertEqual(
132+
parse_newfragment_basename("+123.feature", ["feature"]),
133+
("+123", "feature", 0),
134+
)

0 commit comments

Comments
 (0)