@@ -48,9 +48,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
48
48
file_type = Path (manifest_file ).name
49
49
logging .debug ("Processing file for line lookup: %s" , manifest_file )
50
50
51
- # ----------------------------------------------------
52
- # 1) JSON-based manifest files
53
- # ----------------------------------------------------
54
51
if file_type in ["package-lock.json" , "Pipfile.lock" , "composer.lock" ]:
55
52
try :
56
53
with open (manifest_file , "r" , encoding = "utf-8" ) as f :
@@ -72,7 +69,6 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
72
69
found_key = key
73
70
found_info = value
74
71
break
75
-
76
72
if found_key and found_info :
77
73
needle_key = f'"{ found_key } ":'
78
74
lines = raw_text .splitlines ()
@@ -88,13 +84,9 @@ def find_line_in_file(packagename: str, packageversion: str, manifest_file: str)
88
84
logging .error ("Error reading %s: %s" , manifest_file , e )
89
85
return 1 , f"Error reading { manifest_file } "
90
86
91
- # ----------------------------------------------------
92
- # 2) Text-based / line-based manifests
93
- # ----------------------------------------------------
94
- # For pnpm-lock.yaml, use a different pattern since its format is YAML.
87
+ # For pnpm-lock.yaml, use a special regex pattern.
95
88
if file_type .lower () == "pnpm-lock.yaml" :
96
- # Example pattern: /bitget-main/19.4.9:
97
- searchstring = rf'/{ re .escape (packagename )} /{ re .escape (packageversion )} :'
89
+ searchstring = rf'^\s*/{ re .escape (packagename )} /{ re .escape (packageversion )} :'
98
90
else :
99
91
search_patterns = {
100
92
"package.json" : rf'"{ packagename } ":\s*"[\^~]?{ re .escape (packageversion )} "' ,
@@ -176,9 +168,9 @@ def create_security_comment_sarif(diff) -> dict:
176
168
based on manifest type and improved <br/> formatting for GitHub SARIF display.
177
169
178
170
This function now:
179
- - Accepts multiple manifest files from alert.introduced_by or alert.manifests .
180
- - Generates an individual SARIF result for each manifest file.
181
- - Appends the manifest file name to the rule ID and name for uniqueness .
171
+ - Processes every alert in diff.new_alerts .
172
+ - For alerts with multiple manifest files, generates an individual SARIF result for each file.
173
+ - Appends the manifest file name to the rule ID and name to make each result unique .
182
174
- Does NOT fall back to 'requirements.txt' if no manifest file is provided.
183
175
- Adds detailed logging to validate our assumptions.
184
176
"""
@@ -211,9 +203,7 @@ def create_security_comment_sarif(diff) -> dict:
211
203
base_rule_id = f"{ pkg_name } =={ pkg_version } "
212
204
severity = alert .severity
213
205
214
- # Log raw alert data for manifest extraction.
215
206
logging .debug ("Alert %s - introduced_by: %s, manifests: %s" , base_rule_id , alert .introduced_by , getattr (alert , 'manifests' , None ))
216
-
217
207
manifest_files = []
218
208
if alert .introduced_by and isinstance (alert .introduced_by , list ):
219
209
for entry in alert .introduced_by :
@@ -232,7 +222,7 @@ def create_security_comment_sarif(diff) -> dict:
232
222
233
223
logging .debug ("Alert %s - using manifest_files for processing: %s" , base_rule_id , manifest_files )
234
224
235
- # For each manifest file, create an individual SARIF result.
225
+ # Create an individual SARIF result for each manifest file .
236
226
for mf in manifest_files :
237
227
logging .debug ("Alert %s - Processing manifest file: %s" , base_rule_id , mf )
238
228
socket_url = Messages .get_manifest_type_url (mf , pkg_name , pkg_version )
@@ -241,7 +231,7 @@ def create_security_comment_sarif(diff) -> dict:
241
231
line_number = 1
242
232
logging .debug ("Alert %s: Manifest %s, line %d: %s" , base_rule_id , mf , line_number , line_content )
243
233
244
- # Create a unique rule id and name by appending the file name .
234
+ # Create a unique rule id and name by appending the manifest file .
245
235
unique_rule_id = f"{ base_rule_id } ({ mf } )"
246
236
rule_name = f"Alert { base_rule_id } ({ mf } )"
247
237
0 commit comments