163163
164164
165165def output_console_comments (diff_report : Diff , sbom_file_name : str = None ) -> None :
166- console_security_comment = Messages .create_console_security_alert_table (diff_report )
167- save_sbom_file (diff_report , sbom_file_name )
168- log .info (f"Socket Full Scan ID: { diff_report .id } " )
169- if not report_pass (diff_report ):
170- log .info ("Security issues detected by Socket Security" )
171- msg = f"\n { console_security_comment } "
172- log .info (msg )
173- if not blocking_disabled :
174- sys .exit (1 )
175- else :
176- log .info ("No New Security issues detected by Socket Security" )
166+ if diff_report .id != "NO_DIFF_RAN" :
167+ console_security_comment = Messages .create_console_security_alert_table (diff_report )
168+ save_sbom_file (diff_report , sbom_file_name )
169+ log .info (f"Socket Full Scan ID: { diff_report .id } " )
170+ if len (diff_report .new_alerts ) > 0 :
171+ log .info ("Security issues detected by Socket Security" )
172+ msg = f"\n { console_security_comment } "
173+ log .info (msg )
174+ if not report_pass (diff_report ) and not blocking_disabled :
175+ sys .exit (1 )
176+ else :
177+ # Means only warning alerts with no blocked
178+ if not blocking_disabled :
179+ sys .exit (5 )
180+ else :
181+ log .info ("No New Security issues detected by Socket Security" )
177182
178183
179184def output_console_json (diff_report : Diff , sbom_file_name : str = None ) -> None :
180- console_security_comment = Messages .create_security_comment_json (diff_report )
181- save_sbom_file (diff_report , sbom_file_name )
182- print (json .dumps (console_security_comment ))
183- if not report_pass (diff_report ) and not blocking_disabled :
184- sys .exit (1 )
185+ if diff_report .id != "NO_DIFF_RAN" :
186+ console_security_comment = Messages .create_security_comment_json (diff_report )
187+ save_sbom_file (diff_report , sbom_file_name )
188+ print (json .dumps (console_security_comment ))
189+ if not report_pass (diff_report ) and not blocking_disabled :
190+ sys .exit (1 )
191+ elif len (diff_report .new_alerts ) > 0 and not blocking_disabled :
192+ # Means only warning alerts with no blocked
193+ sys .exit (5 )
185194
186195
187196def report_pass (diff_report : Diff ) -> bool :
@@ -299,11 +308,12 @@ def main_code():
299308 default_branch = scm .is_default_branch
300309
301310 base_api_url = os .getenv ("BASE_API_URL" ) or None
302- core = Core (token = api_token , request_timeout = 1200 , base_api_url = base_api_url )
311+ core = Core (token = api_token , request_timeout = 1200 , base_api_url = base_api_url , allow_unverified = allow_unverified )
303312 no_change = True
304313 if ignore_commit_files :
305314 no_change = False
306315 elif is_repo and files is not None and len (files ) > 0 :
316+ log .info (files )
307317 no_change = core .match_supported_files (files )
308318
309319 set_as_pending_head = False
@@ -319,7 +329,8 @@ def main_code():
319329 make_default_branch = default_branch ,
320330 set_as_pending_head = set_as_pending_head
321331 )
322- diff = None
332+ diff = Diff ()
333+ diff .id = "NO_DIFF_RAN"
323334 if scm is not None and scm .check_event_type () == "comment" :
324335 log .info ("Comment initiated flow" )
325336 log .debug (f"Getting comments for Repo { scm .repository } for PR { scm .pr_number } " )
@@ -329,10 +340,11 @@ def main_code():
329340 elif scm is not None and scm .check_event_type () != "comment" :
330341 log .info ("Push initiated flow" )
331342 diff : Diff
332- diff = core .create_new_diff (target_path , params , workspace = target_path , no_change = no_change )
333343 if no_change :
334- log .info ("No dependency changes" )
344+ log .info ("No manifest files changes, skipping scan" )
345+ # log.info("No dependency changes")
335346 elif scm .check_event_type () == "diff" :
347+ diff = core .create_new_diff (target_path , params , workspace = target_path , no_change = no_change )
336348 log .info ("Starting comment logic for PR/MR event" )
337349 log .debug (f"Getting comments for Repo { scm .repository } for PR { scm .pr_number } " )
338350 comments = scm .get_comments_for_pr (repo , str (pr_number ))
0 commit comments