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

Fix: handle subpackage tags in is_backport #344

Merged
53 changes: 40 additions & 13 deletions tagbot/action/changelog.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll run the CI once this merges. Thank you so much for the fast fix! My only comment is to remember to remove the _is_backport: from the logging statement.

Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,46 @@ def _previous_release(self, version_tag: str) -> Optional[GitRelease]:

def _is_backport(self, version: str) -> bool:
"""Determine whether or not the version is a backport."""
cur_ver = VersionInfo.parse(version[1:])
for r in self._repo._repo.get_releases():
if not r.tag_name.startswith("v"):
continue
try:
ver = VersionInfo.parse(r.tag_name[1:])
except ValueError:
continue
if ver.prerelease or ver.build:
continue
if ver > cur_ver:
return True
return False
try:
# Regular expression to match version tags with or without prefix
version_pattern = re.compile(r"^(.*[-v]?)(\d+\.\d+\.\d+)$")

# Extract the version number from the input
match = version_pattern.match(version)
if not match:
raise ValueError("Invalid version format: ${version}")

# Extract the base version without the 'v' prefix
cur_ver = VersionInfo.parse(match.group(2))
package_name = match.group(1).strip("-v")

for r in self._repo._repo.get_releases():
tag_match = version_pattern.match(r.tag_name)
if not tag_match:
continue

tag_package_name = tag_match.group(1).strip("-v")
if tag_package_name != package_name:
continue

try:
tag_ver = VersionInfo.parse(tag_match.group(2))
except ValueError:
continue

# Disregard prerelease and build versions
if tag_ver.prerelease or tag_ver.build:
continue

# Check if the version is a backport
if tag_ver > cur_ver:
return True

return False
except Exception as e:
# This is a best-effort function so we don't fail the entire process
logger.error(f"Checking if backport failed. Assuming False: {e}")
return False

def _issues_and_pulls(
self, start: datetime, end: datetime
Expand Down