Skip to content

Commit

Permalink
Improve _is_backport
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Sep 14, 2024
1 parent adfb5e2 commit cdabc45
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tagbot/action/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,26 @@ def _previous_release(self, version_tag: str) -> Optional[GitRelease]:
prev_ver = ver
return prev_rel

VERSION_PATTERN = re.compile(r"^(.*?)[-v]?(\d+\.\d+\.\d+(?:\.\d+)*)(?:[-+].+)?$")

def _is_backport(self, version: str) -> bool:
"""Determine whether or not the version is a backport."""
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)
match = VERSION_PATTERN.match(version)
if not match:
raise ValueError("Invalid version format: ${version}")
raise ValueError(f"Invalid version format: {version}")

# Extract the base version without the 'v' prefix
package_name = match.group(1)
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)
tag_match = VERSION_PATTERN.match(r.tag_name)
if not tag_match:
continue

tag_package_name = tag_match.group(1).strip("-v")
tag_package_name = tag_match.group(1)

if tag_package_name != package_name:
continue

Expand All @@ -107,7 +106,9 @@ def _is_backport(self, version: str) -> bool:
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}")
logger.error(
f"Checking if backport failed for version {version}. Assuming False: {e}"
)
return False

def _issues_and_pulls(
Expand Down

0 comments on commit cdabc45

Please sign in to comment.