Skip to content

Commit

Permalink
Fix: handle subpackage tags in is_backport (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Sep 14, 2024
1 parent da659ec commit 2370975
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions tagbot/action/changelog.py
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

0 comments on commit 2370975

Please sign in to comment.