@@ -37,10 +37,10 @@ def remove_alerts(comments: dict, new_alerts: list) -> list:
3737 if ignore_all :
3838 break
3939 else :
40- full_name = f" { alert . pkg_type } / { alert . pkg_name } "
41- purl = ( full_name , alert .pkg_version )
42- purl_star = ( full_name , "*" )
43- if purl in ignore_commands or purl_star in ignore_commands :
40+ if any (
41+ Comments . is_ignore ( alert . pkg_name , alert .pkg_version , name , version , alert . pkg_type )
42+ for name , version in ignore_commands
43+ ) :
4444 log .info (f"Alerts for { alert .pkg_name } @{ alert .pkg_version } ignored" )
4545 else :
4646 log .info (f"Adding alert { alert .type } for { alert .pkg_name } @{ alert .pkg_version } " )
@@ -66,20 +66,28 @@ def get_ignore_options(comments: dict) -> [bool, list]:
6666 ignore_all = True
6767 else :
6868 command = command .lstrip ("ignore" ).strip ()
69- name , version = command .split ("@" )
70- data = (name , version )
69+ name , separator , version = command .rpartition ("@" )
70+ if not separator or not name or not version :
71+ raise ValueError ("Expected package@version" )
72+ data = (name .strip (), version .strip ())
7173 ignore_commands .append (data )
7274 except Exception as error :
7375 log .error (f"Unable to process ignore command for { comment } " )
7476 log .error (error )
7577 return ignore_all , ignore_commands
7678
7779 @staticmethod
78- def is_ignore (pkg_name : str , pkg_version : str , name : str , version : str ) -> bool :
79- result = False
80- if pkg_name == name and (pkg_version == version or version == "*" ):
81- result = True
82- return result
80+ def is_ignore (
81+ pkg_name : str , pkg_version : str , name : str , version : str ,
82+ pkg_type : str = ""
83+ ) -> bool :
84+ package_names = {pkg_name }
85+ if pkg_type :
86+ package_names .add (f"{ pkg_type } /{ pkg_name } " )
87+ target_names = {name }
88+ if not pkg_type and "/" in name :
89+ target_names .add (name .split ("/" , 1 )[1 ])
90+ return bool (package_names & target_names ) and (pkg_version == version or version == "*" )
8391
8492 @staticmethod
8593 def is_heading_line (line ) -> bool :
@@ -187,7 +195,7 @@ def process_updated_security_comment(
187195 # Extract package name and version from the comment
188196 try :
189197 start_marker = stripped [len ("<!-- start-socket-alert-" ):- 4 ] # Strip the comment markers
190- pkg_name , pkg_version = start_marker .split ("@" ) # Extract pkg_name and pkg_version
198+ pkg_name , pkg_version = start_marker .rsplit ("@" , 1 )
191199 except ValueError :
192200 pkg_name , pkg_version = "" , ""
193201
0 commit comments