@@ -45,7 +45,7 @@ def remove_alerts(comments: dict, new_alerts: list) -> list:
4545 break
4646 else :
4747 if any (
48- Comments .is_ignore (alert . pkg_name , alert . pkg_version , name , version , alert . pkg_type )
48+ Comments .matches_issue (alert , name , version )
4949 for name , version in ignore_commands
5050 ):
5151 log .info (f"Alerts for { alert .pkg_name } @{ alert .pkg_version } ignored" )
@@ -83,6 +83,13 @@ def get_ignore_options(comments: dict) -> [bool, list]:
8383 log .error (error )
8484 return ignore_all , ignore_commands
8585
86+ @staticmethod
87+ def matches_issue (alert : Issue , name : str , version : str ) -> bool :
88+ return any (
89+ Comments .is_ignore (package_name , alert .pkg_version , name , version , alert .pkg_type )
90+ for package_name in {alert .pkg_name , alert .package_name_with_namespace ()}
91+ )
92+
8693 @staticmethod
8794 def is_ignore (
8895 pkg_name : str , pkg_version : str , name : str , version : str ,
@@ -240,7 +247,6 @@ def process_updated_security_comment(
240247 )
241248 for line in comment .body_list
242249 )
243- pkg_name = pkg_version = "" # Track current package and version
244250
245251 # Loop through the comment lines
246252 for line in comment .body_list :
@@ -251,18 +257,8 @@ def process_updated_security_comment(
251257
252258 # Detect the start of an alert section
253259 if stripped .startswith ("<!-- start-socket-alert-" ):
254- # Extract package name and version from the comment
255- try :
256- start_marker = stripped [len ("<!-- start-socket-alert-" ):- 4 ] # Strip the comment markers
257- pkg_name , pkg_version = start_marker .rsplit ("@" , 1 )
258- except ValueError :
259- pkg_name , pkg_version = "" , ""
260-
261- # Determine if we should ignore this alert
262- ignore_section = ignore_all or any (
263- Comments .is_ignore (pkg_name , pkg_version , name , version )
264- for name , version in ignore_commands
265- )
260+ marker = stripped .removeprefix ("<!-- start-socket-alert-" ).removesuffix (" -->" )
261+ ignore_section = ignore_all or Comments .matches_alert_marker (marker , ignore_commands )
266262
267263 # If not ignored, include this start marker
268264 if not ignore_section :
@@ -288,6 +284,23 @@ def process_updated_security_comment(
288284
289285 return Messages .normalize_comment_html ("\n " .join (lines ))
290286
287+ @staticmethod
288+ def matches_alert_marker (marker : str , ignore_commands : list [tuple [str , str ]]) -> bool :
289+ coordinate , separator , pkg_version = marker .rpartition ("@" )
290+ if not separator :
291+ return False
292+ prefix = Messages .QUALIFIED_ALERT_MARKER_PREFIX
293+ if coordinate .startswith (prefix ):
294+ pkg_type , _ , pkg_name = coordinate .removeprefix (prefix ).partition ("/" )
295+ names = {pkg_name , pkg_name .rsplit ("/" , 1 )[- 1 ]}
296+ else :
297+ pkg_type , names = "" , {coordinate }
298+ return any (
299+ Comments .is_ignore (pkg_name , pkg_version , name , version , pkg_type )
300+ for name , version in ignore_commands
301+ for pkg_name in names
302+ )
303+
291304 @staticmethod
292305 def extract_alert_details_from_row (row : str , ignore_all : bool , ignore_commands : list [tuple [str , str ]]) -> tuple :
293306 """
0 commit comments