twisted / towncrier

Manage the release notes for your project.

Home Page:https://towncrier.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

orphan fragments that contain a number in the filename are linked to issues.

mdellweg opened this issue · comments

e.g. calling the fragment CHANGES/+compat.somelib_1.12.feature will link the supposed orphan snippet to the issue #12.

Thanks for the report

It looks like we have some missing automated tests.

I think that the fix can start by writing an automated test (or updating the current one) for this filename and see the test failing.

I think that the issue is somewhere here:

for basename in files:
ticket, category, counter = parse_newfragment_basename(
basename, frag_type_names
)
if category is None:
continue
assert ticket is not None
assert counter is not None
if orphan_prefix and ticket.startswith(orphan_prefix):
ticket = ""
# Use and increment the orphan news fragment counter.
counter = orphan_fragment_counter[category]
orphan_fragment_counter[category] += 1

or here

def parse_newfragment_basename(
basename: str, frag_type_names: Iterable[str]
) -> tuple[str, str, int] | tuple[None, None, None]:
invalid = (None, None, None)
parts = basename.split(".")
if len(parts) == 1:
return invalid
if len(parts) == 2:
ticket, category = parts
ticket = strip_if_integer_string(ticket)
return (ticket, category, 0) if category in frag_type_names else invalid
# There are at least 3 parts. Search for a valid category from the second
# part onwards.
# The category is used as the reference point in the parts list to later
# infer the issue number and counter value.
for i in range(1, len(parts)):
if parts[i] in frag_type_names:
# Current part is a valid category according to given definitions.
category = parts[i]
# Use the previous part as the ticket number.
# 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(parts[i - 1])
counter = 0
# Use the following part as the counter if it exists and is a valid
# digit.
if len(parts) > (i + 1) and parts[i + 1].isdigit():
counter = int(parts[i + 1])
return ticket, category, counter
else:
# No valid category found.
return invalid

I would be happy to review a fix for this :)

I started adding to a test: #564
Do you want to see it red before fixing it?

Also your two code snippets are the same. Did you mention to point me to another area too?

Awesome. I have enabled the tests on that PR.

I have updated the code link