diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index 3d863548..a72a3982 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -13,15 +13,6 @@ from jinja2 import Template -def strip_if_integer_string(s: str) -> str: - try: - i = int(s) - except ValueError: - return s - - return str(i) - - # Returns ticket, category and counter or (None, None, None) if the basename # could not be parsed or doesn't contain a valid category. def parse_newfragment_basename( @@ -45,7 +36,11 @@ def parse_newfragment_basename( # NOTE: This allows news fragment names like fix-1.2.3.feature or # something-cool.feature.ext for projects that don't use ticket # numbers in news fragment names. - ticket = strip_if_integer_string(".".join(parts[0:i])) + ticket = ".".join(parts[0:i]).strip() + # If the ticket is an integer, remove any leading zeros (to resolve + # issue #126). + if ticket.isdigit(): + ticket = str(int(ticket)) counter = 0 # Use the following part as the counter if it exists and is a valid # digit. diff --git a/src/towncrier/newsfragments/588.bugfix b/src/towncrier/newsfragments/588.bugfix new file mode 100644 index 00000000..f1c3e8ef --- /dev/null +++ b/src/towncrier/newsfragments/588.bugfix @@ -0,0 +1 @@ +Orphan news fragments, fragments not associated with an issue, consisting of only digits (e.g. '+12345678.feature') now retain their leading marker character. diff --git a/src/towncrier/test/test_builder.py b/src/towncrier/test/test_builder.py index b62033ac..9608e0a2 100644 --- a/src/towncrier/test/test_builder.py +++ b/src/towncrier/test/test_builder.py @@ -125,3 +125,10 @@ def test_orphan_with_dotted_number(self): parse_newfragment_basename("+orphan_12.3.feature", ["feature"]), ("+orphan_12.3", "feature", 0), ) + + def test_orphan_all_digits(self): + """Orphaned snippets can consist of only digits.""" + self.assertEqual( + parse_newfragment_basename("+123.feature", ["feature"]), + ("+123", "feature", 0), + )