Skip to content

Commit

Permalink
Fix incorrect handling of orphan fragment names consists of only digi…
Browse files Browse the repository at this point in the history
…ts (#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]>
  • Loading branch information
SmileyChris and adiroiban authored Apr 27, 2024
1 parent 2908a62 commit 50fc1e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/588.bugfix
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions src/towncrier/test/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

0 comments on commit 50fc1e6

Please sign in to comment.