@@ -69,19 +69,46 @@ def _previous_release(self, version_tag: str) -> Optional[GitRelease]:
6969
7070 def _is_backport (self , version : str ) -> bool :
7171 """Determine whether or not the version is a backport."""
72- cur_ver = VersionInfo .parse (version [1 :])
73- for r in self ._repo ._repo .get_releases ():
74- if not r .tag_name .startswith ("v" ):
75- continue
76- try :
77- ver = VersionInfo .parse (r .tag_name [1 :])
78- except ValueError :
79- continue
80- if ver .prerelease or ver .build :
81- continue
82- if ver > cur_ver :
83- return True
84- return False
72+ try :
73+ # Regular expression to match version tags with or without prefix
74+ version_pattern = re .compile (r"^(.*[-v]?)(\d+\.\d+\.\d+)$" )
75+
76+ # Extract the version number from the input
77+ match = version_pattern .match (version )
78+ if not match :
79+ raise ValueError ("Invalid version format: ${version}" )
80+
81+ # Extract the base version without the 'v' prefix
82+ cur_ver = VersionInfo .parse (match .group (2 ))
83+ package_name = match .group (1 ).strip ("-v" )
84+
85+ for r in self ._repo ._repo .get_releases ():
86+ tag_match = version_pattern .match (r .tag_name )
87+ if not tag_match :
88+ continue
89+
90+ tag_package_name = tag_match .group (1 ).strip ("-v" )
91+ if tag_package_name != package_name :
92+ continue
93+
94+ try :
95+ tag_ver = VersionInfo .parse (tag_match .group (2 ))
96+ except ValueError :
97+ continue
98+
99+ # Disregard prerelease and build versions
100+ if tag_ver .prerelease or tag_ver .build :
101+ continue
102+
103+ # Check if the version is a backport
104+ if tag_ver > cur_ver :
105+ return True
106+
107+ return False
108+ except Exception as e :
109+ # This is a best-effort function so we don't fail the entire process
110+ logger .error (f"Checking if backport failed. Assuming False: { e } " )
111+ return False
85112
86113 def _issues_and_pulls (
87114 self , start : datetime , end : datetime
0 commit comments