@@ -234,7 +234,7 @@ def scan_documents(context: click.Context, documents_to_scan: List[Document], is
234234 cycode_client = context .obj ["client" ]
235235 scan_type = context .obj ["scan_type" ]
236236 severity_threshold = context .obj ["severity_threshold" ]
237- scan_command_type = context .info_name
237+ command_scan_type = context .info_name
238238 error_message = None
239239 all_detections_count = 0
240240 output_detections_count = 0
@@ -246,7 +246,7 @@ def scan_documents(context: click.Context, documents_to_scan: List[Document], is
246246 scan_result = perform_scan (cycode_client , zipped_documents , scan_type , scan_id , is_git_diff , is_commit_range ,
247247 scan_parameters )
248248 all_detections_count , output_detections_count = \
249- handle_scan_result (context , scan_result , scan_command_type , scan_type , severity_threshold ,
249+ handle_scan_result (context , scan_result , command_scan_type , scan_type , severity_threshold ,
250250 documents_to_scan )
251251 scan_completed = True
252252 except Exception as e :
@@ -259,7 +259,7 @@ def scan_documents(context: click.Context, documents_to_scan: List[Document], is
259259 {'all_violations_count' : all_detections_count , 'relevant_violations_count' : output_detections_count ,
260260 'scan_id' : str (scan_id ), 'zip_file_size' : zip_file_size })
261261 _report_scan_status (context , scan_type , str (scan_id ), scan_completed , output_detections_count ,
262- all_detections_count , len (documents_to_scan ), zip_file_size , scan_command_type , error_message )
262+ all_detections_count , len (documents_to_scan ), zip_file_size , command_scan_type , error_message )
263263
264264
265265def scan_commit_range_documents (context : click .Context , from_documents_to_scan : List [Document ],
@@ -309,10 +309,10 @@ def should_scan_documents(from_documents_to_scan: List[Document], to_documents_t
309309 return len (from_documents_to_scan ) > 0 or len (to_documents_to_scan ) > 0
310310
311311
312- def handle_scan_result (context , scan_result , scan_command_type , scan_type , severity_threshold , to_documents_to_scan ):
312+ def handle_scan_result (context , scan_result , command_scan_type , scan_type , severity_threshold , to_documents_to_scan ):
313313 document_detections_list = enrich_scan_result (scan_result , to_documents_to_scan )
314314 relevant_document_detections_list = exclude_irrelevant_scan_results (document_detections_list , scan_type ,
315- scan_command_type , severity_threshold )
315+ command_scan_type , severity_threshold )
316316 context .obj ['report_url' ] = scan_result .report_url
317317 print_results (context , relevant_document_detections_list )
318318 context .obj ['issue_detected' ] = len (relevant_document_detections_list ) > 0
@@ -424,10 +424,10 @@ def enrich_scan_result(scan_result: ZippedFileScanResult, documents_to_scan: Lis
424424
425425
426426def exclude_irrelevant_scan_results (document_detections_list : List [DocumentDetections ], scan_type : str ,
427- scan_command_type : str , severity_threshold : str ) -> List [DocumentDetections ]:
427+ command_scan_type : str , severity_threshold : str ) -> List [DocumentDetections ]:
428428 relevant_document_detections_list = []
429429 for document_detections in document_detections_list :
430- relevant_detections = exclude_irrelevant_detections (scan_type , scan_command_type , severity_threshold ,
430+ relevant_detections = exclude_irrelevant_detections (scan_type , command_scan_type , severity_threshold ,
431431 document_detections .detections )
432432 if relevant_detections :
433433 relevant_document_detections_list .append (DocumentDetections (document = document_detections .document ,
@@ -540,9 +540,9 @@ def exclude_irrelevant_files(context: click.Context, filenames: List[str]) -> Li
540540 return [filename for filename in filenames if _is_relevant_file_to_scan (scan_type , filename )]
541541
542542
543- def exclude_irrelevant_detections (scan_type : str , scan_command_type : str , severity_threshold : str , detections ) -> List :
543+ def exclude_irrelevant_detections (scan_type : str , command_scan_type : str , severity_threshold : str , detections ) -> List :
544544 relevant_detections = exclude_detections_by_exclusions_configuration (scan_type , detections )
545- relevant_detections = exclude_detections_by_scan_command_type ( scan_command_type , relevant_detections )
545+ relevant_detections = exclude_detections_by_scan_type ( scan_type , command_scan_type , relevant_detections )
546546 relevant_detections = exclude_detections_by_severity (scan_type , severity_threshold , relevant_detections )
547547
548548 return relevant_detections
@@ -557,14 +557,18 @@ def exclude_detections_by_severity(scan_type: str, severity_threshold: str, dete
557557 severity_threshold )]
558558
559559
560- def exclude_detections_by_scan_command_type ( scan_command_type : str , detections ) -> List :
561- if scan_command_type != PRE_COMMIT_SCAN_COMMAND_TYPE :
562- return detections
560+ def exclude_detections_by_scan_type ( scan_type : str , command_scan_type : str , detections ) -> List :
561+ if command_scan_type == PRE_COMMIT_COMMAND_SCAN_TYPE :
562+ return exclude_detections_in_deleted_lines ( detections )
563563
564- return exclude_detections_for_pre_commit_scan_command_type (detections )
564+ if command_scan_type in COMMIT_RANGE_BASED_COMMAND_SCAN_TYPES \
565+ and scan_type == SECRET_SCAN_TYPE \
566+ and configuration_manager .get_should_exclude_detections_in_deleted_lines (command_scan_type ):
567+ return exclude_detections_in_deleted_lines (detections )
568+ return detections
565569
566570
567- def exclude_detections_for_pre_commit_scan_command_type (detections ) -> List :
571+ def exclude_detections_in_deleted_lines (detections ) -> List :
568572 return [detection for detection in detections if detection .detection_details .get ('line_type' ) != 'Removed' ]
569573
570574
@@ -795,7 +799,7 @@ def _handle_exception(context: click.Context, e: Exception):
795799
796800def _report_scan_status (context : click .Context , scan_type : str , scan_id : str , scan_completed : bool ,
797801 output_detections_count : int , all_detections_count : int , files_to_scan_count : int ,
798- zip_size : int , scan_command_type : str , error_message : Optional [str ]):
802+ zip_size : int , command_scan_type : str , error_message : Optional [str ]):
799803 try :
800804 cycode_client = context .obj ["client" ]
801805 end_scan_time = time .time ()
@@ -806,7 +810,7 @@ def _report_scan_status(context: click.Context, scan_type: str, scan_id: str, sc
806810 'all_detections_count' : all_detections_count ,
807811 'scannable_files_count' : files_to_scan_count ,
808812 'status' : 'Completed' if scan_completed else 'Error' ,
809- 'scan_command_type' : scan_command_type ,
813+ 'scan_command_type' : command_scan_type ,
810814 'operation_system' : platform (),
811815 'error_message' : error_message
812816 }
0 commit comments